其实是很裸的dp,竟然放在第四题==

dp[i][j]表示当前放j和为i的方案数

dp[0][0]=1;

dp[i][j]=dp[i-j][j-1]+dp[i-j][j];

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<math.h>
 4 #include<algorithm>
 5 using namespace std;
 6 int dp[50005][320];
 7 int main()
 8 {
 9   int T,t,n,m,x,i,j,ans;
10   scanf("%d",&T);
11   for (t=1;t<=T;t++)
12   {
13     scanf("%d%d",&n,&m);
14     x=((int)sqrt(1.0*8*n+1.0)-1)/2;
15     memset(dp,0,sizeof(dp));
16     dp[0][0]=1;
17     for (i=1;i<=n;i++)
18       for (j=1;j<=min(x,i);j++)
19         dp[i][j]=(dp[i-j][j-1]+dp[i-j][j])%m;
20     ans=0;
21     for (i=1;i<=x;i++)
22       ans=(ans+dp[n][i])%m;
23     printf("Case #%d: %d\n",t,ans);
24   }
25   return 0;
26 }
View Code

相关文章:

  • 2021-06-22
  • 2022-01-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-21
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-05
  • 2021-11-07
  • 2022-02-13
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案