日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【DP】HDU 2189 悼念512汶川大地震遇难同胞——来生一起走

發(fā)布時間:2023/12/18 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【DP】HDU 2189 悼念512汶川大地震遇难同胞——来生一起走 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

打一個小于150的素數(shù)表

為了分成的組的人數(shù)不重復用dp[i][j] 表示

i表示i個人 j表示分成的組內(nèi)的最大素數(shù)序號


#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;//點數(shù)的最大值 const int MAXM = 20006;//邊數(shù)的最大值 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;//點數(shù)的最大值 const int MAXM = 20006;//邊數(shù)的最大值 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汶川大地震遇难同胞——来生一起走的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。