标签:des blog http ar io color os 使用 sp
Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 876 Accepted Submission(s): 329
dp[i][j] 表示前i堆石子构成长度为j的串的方案数;
状态转移方程是:k为i堆使用的数量
dp[i][j] = (dp[i][j] + dp[i-1][j-k] * C[j][k]%M)%M;
自己写挫了,上一大神代码。
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; #define M 1000000007 long long dp[110][10010]; long long C[11000][110]; void cc() { int i,j; C[0][0]=1; for(i=1;i<10010;i++) for(j=0;j<=100;j++) if(j == 0) C[i][j] = C[i-1][j]; else C[i][j] = (C[i-1][j]+C[i-1][j-1])%M; //C[i][j]=(j==0) ? C[i-1][j] : (); } int main() { cc(); int n; int cas = 1; while(cin >> n) { memset(dp,0,sizeof(dp)); dp[0][0] = 1; int sum = 0; for(int i = 1;i <= n;i++) { int t; cin >> t; sum += t; for(int k = 0;k <= t;k++) for(int j = k;j <= sum;j++) dp[i][j] = (dp[i][j] + dp[i-1][j-k] * C[j][k]%M)%M; } long long re = 0; for(int i = 1;i <= sum;i++) re = (re + dp[n][i])%M; cout << "Case " << cas++<< ": " << re << "\n"; } return 0; }
标签:des blog http ar io color os 使用 sp
原文地址:http://www.cnblogs.com/a972290869/p/4166265.html