http://acm.jlu.edu.cn/joj/showproblem.php?pid=1595 此题是求组合数问题,即求C(n,m)问题,根据组合公式C(n,m)=C(n-1,m)+C(n-1,m-1)可以将此题转化成大数加法 #include<stdio.h> #include<string.h> void add(char a[],char b[],char c[]){ int dig=0,temp,i; for(i=0;a[i]!='/0'&&b[i]!='/0';i++){ temp=a[i]-'0'+(b[i]-'0')+dig; dig=temp/10; c[i]=temp%10+'0'; } if(a[i]!='/0'){ while(a[i]!='/0'){ temp=a[i]-'0'+dig; c[i]=temp%10+'0'; dig=temp/10; i++; } } else if(b[i]!='/0'){ while(b[i]!='/0'){ temp=b[i]-'0'+dig; c[i]=temp%10+'0'; dig=temp/10; i++; } } if(dig==1){ c[i]='1'; c[i+1]='/0'; } else c[i]='/0'; } int main(){ int n,m,i,j,t,k; char c[102][102][200]; for(i=1;i<=100;i++){ c[i][i][0]=c[i][0][0]='1'; c[i][i][1]=c[i][0][1]='/0'; t=i; k=0; while(t!=0){ c[i][1][k]=t%10+'0'; t/=10; k++; } c[i][1][k]='/0'; } for(i=2;i<=100;i++) for(j=2;j<i;j++) add(c[i-1][j-1],c[i-1][j],c[i][j]); while(scanf("%d%d",&n,&m)!=EOF,n){ printf("%d things taken %d at a time is ",n,m); j=strlen(c[n][m])-1; for(i=j;i>=0;i--) printf("%c",c[n][m][i]); printf(" exactly./n"); } return 0; }