Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12639 Accepted Submission(s): 8929
4 10 20
5 42 627
#include<stdio.h> int main() { int n,i,j,k; int a[1010],b[1010];//这个根据题目要求灵活变化 while(~scanf("%d",&n))//要是有对n的其他限制条件也可以在此 说明 加以限制 { for(i=0;i<=n;i++) a[i]=1,b[i]=0; for(i=2;i<=n;i++) { for(j=0;j<=n;j++) for(k=0;k+j<=n;k+=i) b[j+k]+=a[j]; for(j=0;j<=n;j++) a[j]=b[j],b[j]=0; } printf("%d\n",a[n]); } return 0; }
<span style="font-size:14px;">#include<stdio.h> int main() { int n; int i,j,k; int a[130],b[130]; for(i=0;i<=129;i++) a[i]=1,b[i]=1; for(i=2;i<=129;i++) { for(j=1;j<=129/i;j++) { for(k=0;k<=129;k++) if(k+j*i<=129) b[k+j*i]+=a[k]; } for(j=0;j<=129;j++) a[j]=b[j]; } while(~scanf("%d",&n)) { printf("%d\n",a[n]); } return 0; }</span>
原文地址:http://blog.csdn.net/ice_alone/article/details/38370713