wmhwuminhao @ 2024-10-20 09:52:23
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll x[25][25][25];
ll a , b , c;
ll w (ll a , ll b , ll c)
{
if (a <= 0 || b <= 0 ||c <= 0) return 1;
if (a > 20 || b > 20 || c > 20) return w(20 , 20 , 20);
if (a < b && b < c)
{
if (x[a][b][c-1] == 0) x[a][b][c-1] = w(a , b , c - 1);
if (x[a][b-1][c-1] == 0) x[a][b-1][c-1] = w(a , b - 1 , c - 1);
if (x[a][b-1][c] == 0) x[a][b-1][c] = w(a , b - 1 , c);
x[a][b][c] = x[a][b][c-1] + x[a][b-1][c-1] + x[a][b-1][c];
}
else
{
if (x[a-1][b][c] == 0) x[a-1][b][c] = w(a - 1 , b , c);
if (x[a-1][b-1][c] == 0) x[a-1][b-1][c] = w(a - 1 , b - 1 , c);
if (x[a-1][b][c-1] == 0) x[a-1][b][c-1] = w(a - 1 , b , c - 1);
if (x[a-1][b-1][c-1] == 0) x[a-1][b-1][c-1] = w(a - 1 , b - 1 , c - 1);
x[a][b][c] = x[a-1][b][c] + x[a-1][b-1][c] + x[a-1][b][c-1] - x[a-1][b-1][c-1];
}
return x[a][b][c];
}
int main ()
{
while (scanf ("%lld%lld%lld" , &a , &b , &c))
{
if ((a == -1) && (b == -1) && (c == -1)) return 0;
printf("w(%lld, %lld, %lld) = ", a, b, c);
printf("%lld\n", w(a, b, c));
}
}
帮我看一看代码错在哪里
by Xlon_Rainfi @ 2024-11-05 22:22:49
@wmhwuminhao x[a][b][c] = x[a][b][c-1] + x[a][b-1][c-1] + x[a][b-1][c];
最后一个加号应改成减号。
by wmhwuminhao @ 2024-11-10 09:59:34
@Xlon_Rainfi 谢谢,我已更正