Jason_LiDongJin @ 2023-02-21 16:41:22
错在哪……
#include <bits/stdc++.h>
#define int long long
using namespace std;
int f[25][25][25];
int w(int a, int b, int c) {
if (a <= 100 && b <= 100 && c <= 100 && f[a][b][c])
return f[a][b][c];
if (a <= 0 || b <= 0 || c <= 0)
return 1;
if (a > 20 || b > 20 || c > 20)
return f[a][b][c] = w(20, 20, 20);
if (a < b && b < c)
return f[a][b][c] = (w(a, b, c - 1) + w(a, b - 1, c - 1) - w(a, b - 1, c));
return 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);
}
signed main() {
int x, y, z;
while (cin >> x >> y >> z) {
if (x == -1 && y == -1 && z == -1)
break;
cout << "w(" << x << ", " << y << ", " << z << ") = " << w(x, y, z) << "\n";
}
return 0;
}
by heike305 @ 2023-02-21 16:49:04
@Jason_LiDongJin if (a <= 100 && b <= 100 && c <= 100 && f[a][b][c])
为什么要a<=100……
by heike305 @ 2023-02-21 16:50:26
if (a > 20 || b > 20 || c > 20)
return f[a][b][c] = w(20, 20, 20);
改成
if (a > 20 || b > 20 || c > 20)
return w(20, 20, 20);
by Jason_LiDongJin @ 2023-02-21 16:59:35
@
by Loser_Syx @ 2023-02-21 17:20:14
@Jason_LiDongJin
#include <bits/stdc++.h>
using namespace std;
int f[25][25][25];
int w(int a, int b, int c) {
if (a <= 0 || b <= 0 || c <= 0)
return 1;
if (a > 20 || b > 20 || c > 20)
return f[a][b][c] = w(20, 20, 20);
if (f[a][b][c])
return f[a][b][c];
if (a < b && b < c)
return f[a][b][c] = (w(a, b, c - 1) + w(a, b - 1, c - 1) - w(a, b - 1, c));
return 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);
}
int main() {
int x, y, z;
while (cin >> x >> y >> z) {
if (x == -1 && y == -1 && z == -1)
break;
cout << "w(" << x << ", " << y << ", " << z << ") = " << w(min(x, 21), min(y, 21), min(z, 21)) << "\n";
}
return 0;
}
by Loser_Syx @ 2023-02-21 17:20:30
@Jason_LiDongJin 帮你改了改,能AC
by heike305 @ 2023-02-21 17:23:50
@Jason_LiDongJin 你放那么多$干嘛
by Loser_Syx @ 2023-02-25 20:19:56
@mooktian 你脑*吗,我操作之前取了最小值