|
|
back to boardWA 1 help me please, here's my code, I don't know why it always gets WA 1 #include <stdio.h> #include <stdlib.h> int findmax(int a, int b) {return (a>b ? a : b);} int mas[1001][1001]; int main(void) { int i,j,a,b,k,max,min; for (i=1;i<1001;i++) { mas[1][i]=1; mas[2][i]=2; mas[i][1]=i; } for (i=3;i<1001;i++) { for (j=2;j<1001;j++) { mas[i][j]=2000;
if (j>5) { if (mas[i][j-1]==mas[i][j-2]) {mas[i][j]=mas[i][j-1]; continue;} }
for (k=2; k<=i; k++) { max=findmax(mas[k-1][j-1],mas[i-k][j])+1; if (mas[i][j]!=2000 && max>mas[i][j]) break; if (max<mas[i][j]) {mas[i][j]=max; min=k;} } } } scanf("%d",&a); scanf("%d",&b);
while (a!=0 && b!=0) { printf("%d\n",mas[b][a]); scanf("%d",&a); scanf("%d",&b); } return 0; } |
|
|