guimei121212 @ 2024-09-27 19:40:27
#include <iostream>
#include <vector>
const int N = 1010;
long long arr[21][21][21];
bool vis[21][21][21] = {false};
int w(long long a, long long b, long long c) {
if (a <= 0 || b <= 0 || c <= 0) {
return 1;
} else if (a > 20 || b > 20 || c > 20) {
return w(20, 20, 20);
} else if (vis[a][b][c]) {
return arr[a][b][c];
}
arr[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);
if (a < b && b < c) {
arr[a][b][c] += w(a, b, c - 1) + w(a, b - 1, c - 1) + w(a, b - 1, c);
}
vis[a][b][c] = true;
return arr[a][b][c];
}
int main() {
long long a, b, c;
std::vector<int> results;
std::vector<int> p;
while (true) {
std::cin >> a >> b >> c;
if (a == -1 && b == -1 && c == -1) {
break;
}
results.push_back(w(a, b, c));
p.push_back(a);
p.push_back(b);
p.push_back(c);
}
for (size_t i = 0; i < results.size(); i++) {
std::cout<<"w(";
std::cout<<p[(i+1)*3-3]<<','<<' '<<p[(i+1)*3-2]<<','<< ' '<<p[(i+1)*3-1]<<')'<<' '<<'='<<' ';
std::cout << results[i] << std::endl;
}
return 0;
}
by 虫二bug2 @ 2024-11-08 00:33:45
@guimei121212 很锻炼debug能力的代码……虽然但是还是改好了:
#include <iostream>
#include <vector>
int arr[21][21][21];
int w(int a, int b, int c) {
if (a <= 0 || b <= 0 || c <= 0) return 1;
if (arr[a][b][c]) return arr[a][b][c];
if (a < b && b < c)arr[a][b][c] = w(a, b, c - 1) + w(a, b - 1, c - 1) - w(a, b - 1, c);
else arr[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 arr[a][b][c];
}
int main() {
long long a, b, c;
std::vector<int> results;
std::vector<long long> p;
while (true) {
std::cin >> a >> b >> c;
if (a == -1 && b == -1 && c == -1)break;
p.push_back(a);
p.push_back(b);
p.push_back(c);
if(a<=0||b<=0||c<=0)a=b=c=0;
if(a>20||b>20||c>20)a=b=c=20;
results.push_back(w(a, b, c));
}
for (size_t i = 0; i < results.size(); i++) {
std::cout<<"w(";
std::cout<<p[(i+1)*3-3]<<','<<' '<<p[(i+1)*3-2]<<','<< ' '<<p[(i+1)*3-1]<<')'<<' '<<'='<<' ';
std::cout << results[i] << std::endl;
}
return 0;
}
by guimei121212 @ 2024-11-08 21:03:47
@虫二bug2 蟹蟹你