【HDOJ】3419 The Three Groups

时间:2022-04-04 15:31:15

记忆化搜索。

 /* 3419 */
#include <cstdio>
#include <cstring>
#include <cstdlib> #define MAXN 10 int ans;
int n[];
int x[];
bool visit[MAXN];
int cnt[MAXN][MAXN][MAXN]; void dfs(int d, int i, int v) {
if (i == ) {
if (x[]*x[] == x[])
++ans;
return ;
}
if (d < n[i]) {
for (int j=; j<MAXN; ++j) {
if (!visit[j]) {
visit[j] = true;
dfs(d+, i, v*+j);
visit[j] = false;
}
}
} else {
x[i] = v;
dfs(, i+, );
}
} int main() {
int a, b, c;
int i, j, k; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif memset(cnt, -, sizeof(cnt));
while (scanf("%d %d %d", &a, &b, &c)!=EOF && (a||b||c)) {
if (a+b < c) {
puts("");
} else if (a>c || b>c){
puts("");
} else if (a+b-c>) {
puts("");
} else if (cnt[a][b][c] >= ) {
printf("%d\n", cnt[a][b][c]);
} else {
memset(visit, false, sizeof(visit));
n[] = a;
n[] = b;
n[] = c;
ans = ;
dfs(, , );
cnt[a][b][c] = ans;
printf("%d\n", ans);
}
} return ;
}