|
|
back to boardI know the recursive , but my prog give WA here . please help me i know the recursive relation . F[l] := (k-1)(F[l-1] + F[l-2]) F[n] := (k-1)(F[n-1]) but my prog give WA here . i don know why . help me please. here is my prog : #include <stdio.h> int n,k,z,lb,a[36],b[36]; void jam() { int temp[36]; int i; for (i=0;i<=lb;i++) temp[i] = b[i]; for (i=0;i<=lb;i++) { b[i] = a[i] + b[i]; if (b[i] > 9) { b[i] = b[i] - 10; b[i+1] = b[i+1] + 1; } } for (i=0;i<=lb;i++) a[i] = temp[i]; if (b[lb+1] > 0) lb++; } void zarb() { int j; for (j = 0 ;j <= lb ; j ++) { b[j] = b[j] * (k-1); if (b[j] > 9) { b[j] = b[j]/10; b[j+1] = b[j+1] + b[j]%10; } } if (b[lb+1] > 0) lb++; } void main(void) { scanf ("%d\n%d",&n,&k); a[0] = 0; b[0] = k; lb = 0; if (b[0] = 10) { b[0] = 0; b[1] = 1; lb = 1; } for (z=1;z<n-1;z++) { jam(); zarb(); } for (z=0;z<=lb;z++) { b[z] = b[z] * (k-1); if (b[z] > 9) { b[z+1] = b[z]/10; b[z] = b[z]%10; } } if (b[lb+1] > 0) lb++; for (z=lb;z>=0;z--) printf ("%d",b[z]); } |
|
|