【DP】HDU 2189 悼念512汶川大地震遇难同胞——来生一起走
生活随笔
收集整理的這篇文章主要介紹了
【DP】HDU 2189 悼念512汶川大地震遇难同胞——来生一起走
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
打一個小于150的素數表
為了分成的組的人數不重復用dp[i][j] 表示
i表示i個人 j表示分成的組內的最大素數序號
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <string> #include <iostream> #include <algorithm> using namespace std; #include <queue> #include <stack> #include <vector> #include <deque> #include <set> #include <map> #define IN freopen ("in.txt" , "r" , stdin); #define OUT freopen ("out.txt" , "w" , stdout); typedef long long LL; const int MAXN = 2111;//點數的最大值 const int MAXM = 20006;//邊數的最大值 const int INF = 11521204; const int mod=1000000007; int prim[222],dp[222][222]; bool yes[155]; int main() {int tol=0;memset(yes,false,sizeof(yes));for(int i=2; i<=150; i++){if(!yes[i]){prim[tol++]=i;for(int j=i+i; j<=150; j+=i)yes[j]=true;}}memset(dp,0,sizeof(dp));for(int i=0; i<tol; i++)dp[0][i]=1;for(int i=0; i<=150; i++){for(int k=0; k<tol; k++){for(int j=0; j<=k; j++){int x=i+prim[j];if(x<=150)dp[x][k]+=dp[i][j];}}}int t,n;scanf("%d",&t);while(t--){scanf("%d",&n);printf("%d\n",dp[n][tol-1]);}return 0; }
再次放錯順序wa掉了 囧rz
一維方程
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <string> #include <iostream> #include <algorithm> using namespace std; #include <queue> #include <stack> #include <vector> #include <deque> #include <set> #include <map> #define IN freopen ("in.txt" , "r" , stdin); #define OUT freopen ("out.txt" , "w" , stdout); typedef long long LL; const int MAXN = 2111;//點數的最大值 const int MAXM = 20006;//邊數的最大值 const int INF = 11521204; const int mod=1000000007; int prim[222],dp[222]; bool yes[155]; int main() {int tol=0;memset(yes,false,sizeof(yes));for(int i=2; i<=150; i++){if(!yes[i]){prim[tol++]=i;for(int j=i+i; j<=150; j+=i)yes[j]=true;}}int t,n;scanf("%d",&t);while(t--){int tr=0;memset(dp,0,sizeof(dp));scanf("%d",&n);dp[0]=1;for(int j=0; j<tol; j++){for(int i=0; i<=n; i++){int x=i+prim[j];if(x<=n)dp[x]+=dp[i];}}printf("%d\n",dp[n]);}return 0; }轉載于:https://www.cnblogs.com/kewowlo/p/4002559.html
總結
以上是生活随笔為你收集整理的【DP】HDU 2189 悼念512汶川大地震遇难同胞——来生一起走的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python MySQL 插入Elast
- 下一篇: horizon