View Code
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #define N 125 5 using namespace std; 6 int c1[N],c2[N]; 7 int main() 8 { 9 int i,j,k,n; 10 for(i=0;i<=120;i++) 11 { 12 c1[i]=1; 13 c2[i]=0; 14 } 15 for(i=2;i<=120;i++) 16 { 17 for(j=0;j<=120;j++) 18 for(k=0;k+j<=120;k+=i) 19 { 20 c2[j+k]+=c1[j]; 21 } 22 for(j=0;j<=120;j++) 23 { 24 c1[j]=c2[j]; 25 c2[j]=0; 26 } 27 } 28 while(~scanf("%d",&n)) 29 { 30 printf("%d\n",c1[n]); 31 } 32 return 0; 33 }
讲解链接:http://www.cnblogs.com/CyWn/archive/2011/08/17/2143671.html