标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 500 Accepted Submission(s): 168
#include <iostream> #include <cstdio> #include <string.h> #include <queue> #include <algorithm> #include <math.h> using namespace std; int dp[320][50005]; int main() { int tcase,t=1; scanf("%d",&tcase); while(tcase--){ int n,m; scanf("%d%d",&n,&m); int k = 0; while(k*(k+1)<=2*n) k++; memset(dp,0,sizeof(dp)); dp[0][0] = 1; for(int i=1;i<=k;i++){ for(int j=i;j<=n;j++){ dp[i][j] = (dp[i][j-i]+dp[i-1][j-i])%m; } } int ans = 0; for(int i=1;i<=k;i++){ ans = (ans+dp[i][n])%m; } printf("Case #%d: %d\n",t++,ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/liyinggang/p/5691186.html