这道题的一些思路分享(c语言的)

P1464 Function

副ac代码: 代码如下:: ```cpp #include<stdio.h> int f[21][21][21]; int aa[10000],bb[10000],cc[10000]; int w(int a,int b,int c) { if(a<=0||b<=0||c<=0) return 1; if(a>20||b>20||c>20) return w(20,20,20); if(f[a][b][c] != f[0][0][0]) return f[a][b][c]; if(a<b&&b<c) f[a][b][c] = w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c); else f[a][b][c] = w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1); return f[a][b][c]; } int main(){ int a,b,c,i,ii; i=0; while(a!=-1||b!=-1||c!=-1){ scanf("%d %d %d",&a,&b,&c); aa[i]=a;bb[i]=b;cc[i]=c; i++; } for(ii=0;ii<i-2;ii++){printf("w(%d, %d, %d) = %d \n",aa[ii],bb[ii],cc[ii],w(aa[ii],bb[ii],cc[ii]));} printf("w(%d, %d, %d) = %d",aa[ii],bb[ii],cc[ii],w(aa[ii],bb[ii],cc[ii])); return 0; } ```
by majinyong @ 2016-07-19 15:20:56


表示我边输入边输出AC了
by H15teve @ 2016-08-08 21:25:55


|