為什麼我的代碼AC不了。
[cpp]
#include <stdio.h>
int v[40001][40001][10];
long int f(int n, int m, int c)
{
if(n==8 && m==8 && c==0)
v[8][8][0] = 0;
if(n==8&&m==8&&c==1)
v[8][8][1] = 1;
if(n==9&&m==8&&c==0)
v[9][8][0] = 1;
if(n==9&&m==8&&c==1)
v[9][8][1] = 1;
if(n>8 && m>8 && c==0)
v[n][m][c] = f(n-1, m-1, 0) + 2;
else if(n>8 && m>8 && c==1)
v[n][m][c] = f(n-1, m-1, 1) + 1;
return v[n][m][c];
}
int main()
{
int n, m, c;
long int result;
while(scanf("%d %d %d", &n, &m, &c) != EOF)
{
if(n == 0 && m == 0 && c == 0)
break;
else
{
if(n >= m)
result = f(n, m, c);
else
result = f(m, n, c);
}
printf("%ld\n", result);
}
return 0;
}
#include <stdio.h>
int v[40001][40001][10];
long int f(int n, int m, int c)
{
if(n==8 && m==8 && c==0)
v[8][8][0] = 0;
if(n==8&&m==8&&c==1)
v[8][8][1] = 1;
if(n==9&&m==8&&c==0)
v[9][8][0] = 1;
if(n==9&&m==8&&c==1)
v[9][8][1] = 1;
if(n>8 && m>8 && c==0)
v[n][m][c] = f(n-1, m-1, 0) + 2;
else if(n>8 && m>8 && c==1)
v[n][m][c] = f(n-1, m-1, 1) + 1;
return v[n][m][c];
}
int main()
{
int n, m, c;
long int result;
while(scanf("%d %d %d", &n, &m, &c) != EOF)
{
if(n == 0 && m == 0 && c == 0)
break;
else
{
if(n >= m)
result = f(n, m, c);
else
result = f(m, n, c);
}
printf("%ld\n", result);
}
return 0;
}
分享到: