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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

HDU - 1223 DP 分类

發布時間:2024/4/15 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU - 1223 DP 分类 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

據說這個是經典問題
\(dp[i][j]=dp[i-1][j-1]*j+dp[i-1][j]*j\)
\(dp[i][j]\)表示前i個數分為j個集合,[i-1][j-1]為插入小于號[i-1][j]為插入等于號
新姿勢get

#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<string> #include<vector> #include<stack> #include<queue> #include<set> #include<map> #define rep(i,j,k) for(register int i=j;i<=k;i++) #define rrep(i,j,k) for(register int i=j;i>=k;i--) #define erep(i,u) for(register int i=head[u];~i;i=nxt[i]) #define iin(a) scanf("%d",&a) #define lin(a) scanf("%lld",&a) #define din(a) scanf("%lf",&a) #define s0(a) scanf("%s",a) #define s1(a) scanf("%s",a+1) #define print(a) printf("%lld",(ll)a) #define enter putchar('\n') #define blank putchar(' ') #define println(a) printf("%lld\n",(ll)a) #define IOS ios::sync_with_stdio(0) using namespace std; const int maxn = 1e3+11; const int oo = 0x3f3f3f3f; const double eps = 1e-7; typedef long long ll; ll read() {ll x=0,f=1;register char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f; } struct BigInt{const static int mod = 10000;const static int DLEN = 4;int a[600],len;BigInt(){memset(a,0,sizeof(a));len = 1;}BigInt(int v){memset(a,0,sizeof(a));len = 0;do{a[len++] = v%mod;v /= mod;}while(v);}BigInt(const char s[]){memset(a,0,sizeof(a));int L = strlen(s);len = L/DLEN;if(L%DLEN)len++;int index = 0;for(int i = L-1;i >= 0;i -= DLEN){int t = 0;int k = i - DLEN + 1;if(k < 0)k = 0;for(int j = k;j <= i;j++)t = t*10 + s[j] - '0';a[index++] = t;}}BigInt operator +(const BigInt &b)const{BigInt res;res.len = max(len,b.len);for(int i = 0;i <= res.len;i++)res.a[i] = 0;for(int i = 0;i < res.len;i++){res.a[i] += ((i < len)?a[i]:0)+((i < b.len)?b.a[i]:0);res.a[i+1] += res.a[i]/mod;res.a[i] %= mod;}if(res.a[res.len] > 0)res.len++;return res;}BigInt operator *(const BigInt &b)const{BigInt res;for(int i = 0; i < len;i++){int up = 0;for(int j = 0;j < b.len;j++){int temp = a[i]*b.a[j] + res.a[i+j] + up;res.a[i+j] = temp%mod;up = temp/mod;}if(up != 0)res.a[i + b.len] = up;}res.len = len + b.len;while(res.a[res.len - 1] == 0 &&res.len > 1)res.len--;return res;}void output(){printf("%d",a[len-1]);for(int i = len-2;i >=0 ;i--)printf("%04d",a[i]);printf("\n");} }; BigInt dp[60][60],UNIT(1); int main(){dp[1][1]=UNIT;rep(i,2,50)rep(j,1,i) dp[i][j]=dp[i-1][j-1]*j+dp[i-1][j]*j;int T=read();while(T--){int n=read();BigInt ans(0);rep(i,1,n) ans=ans+dp[n][i];ans.output();}return 0; }

轉載于:https://www.cnblogs.com/caturra/p/8515450.html

總結

以上是生活随笔為你收集整理的HDU - 1223 DP 分类的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。