BismarkSea @ 2023-07-16 23:04:06
大佬帮忙看一看
#include <iostream>
long long f[21][21][21];
long long w(long long a, long long b, long long c) {
if (f[a][b][c] != 0)return f[a][b][c];
else if (a == 0 || b == 0 || c == 0)f[a][b][c] = 1;
else 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(){
using namespace std;
long long a = 0, b = 0, c = 0;
while (1) {
cin >> a>>b>>c;
if (a == -1&&b==-1&&c==-1)break;
printf("w(%lld, %lld, %lld) = ",a, b, c);
if (a < 0)a = 0; if (b < 0)b = 0; if (c < 0)c = 0;
if (a > 20 || b > 20 || c >20) {a=20;b = 20; c = 20;}
printf("%lld\n", w(a, b, c));
}
return 0;
}
by Misophiliac @ 2023-07-16 23:21:13
@BismarkSea
#include <iostream>
long long f[21][21][21];
long long w(long long a, long long b, long long 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] != 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(){
using namespace std;
long long a = 0, b = 0, c = 0;
while (1) {
cin >> a>>b>>c;
if (a == -1&&b==-1&&c==-1)break;
printf("w(%lld, %lld, %lld) = ",a, b, c);
printf("%lld\n", w(a, b, c));
}
return 0;
}
by BismarkSea @ 2023-07-17 12:35:54
AC了,谢谢大佬