九野的博客,转载请注明出处: http://blog.csdn.net/acmmmm/article/details/9832933
题意:n的划分个数,是组合数,排列不重复计算
水题mark
#include<stdio.h> #include<string.h> #define N 130 int dp[N][N]; int Maxn[N][N]; int main(){ memset(dp,0,sizeof(dp)); memset(Maxn,0,sizeof(Maxn)); int i,j,n; dp[1][1]=1; Maxn[0][0]=1; Maxn[1][1]=1; for(i=2;i<N;i++) for(j=1;j<=i;j++) { if(i-j<=j)dp[i][j]=Maxn[i-j][i-j]; else dp[i][j]=Maxn[i-j][j]; Maxn[i][j]=dp[i][j]+Maxn[i][j-1]; } while(~scanf("%d",&n)) printf("%d\n",Maxn[n][n]); return 0; }
也可以打表,n只有120所以随便来一下
#include"stdio.h" int a[120]={1,2,3,5,7,11,15,22,30,42,56,77,101,135,176,231,297,385,490,627,792,1002,1255,1575,1958, 2436,3010,3718,4565,5604,6842,8349,10143,12310,14883,17977,21637,26015,31185,37338,44583,53174,63261, 75175,89134,105558,124754,147273,173525,204226,239943,281589,329931,386155,451276,526823,614154,715220, 831820,966467,1121505,1300156,1505499,1741630,2012558,2323520,2679689,3087735,3554345,4087968,4697205,5392783, 6185689,7089500,8118264,9289091,10619863,12132164,13848650,15796476,18004327,20506255,23338469,26543660, 30167357,34262962,38887673,44108109,49995925,56634173,64112359,72533807,82010177,92669720,104651419,118114304, 133230930,150198136,169229875,190569292,214481126,241265379,271248950,304801365,342325709,384276336,431149389, 483502844,541946240,607163746,679903203,761002156,851376628,952050665,1064144451,1188908248,1327710076,1482074143, 1653668665,1844349560}; int main(){ int n; while(~scanf("%d",&n)) printf("%d\n",a[n-1]); }