分析:用三维数组来记录状态,然后分类DFS
Code:
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; int A, B, C; bool st[25][25][25]; int ans[25], cnt; bool vis[25]; void dfs(int a, int b, int c) { if(st[a][b][c]) return; st[a][b][c] = true; if(a == 0 && !vis[c]) ans[cnt++] = c; if(a <= B-b) dfs(0, b+a, c); else dfs(a-(B-b), B, c); if(a <= C-c) dfs(0, b, c+a); else dfs(a-(C-c), b, C); if(b <= A-a) dfs(a+b, 0, c); else dfs(A, b-(A-a), c); if(b <= C-c) dfs(a, 0, c+b); else dfs(a, b-(C-c), C); if(c <= A-a) dfs(a+c, b, 0); else dfs(A, b, c-(A-a)); if(c <= B-b) dfs(a, b+c, 0); else dfs(a, B, c-(B-b)); } int main() { while(~scanf("%d%d%d", &A, &B, &C)) { memset(ans, 0, sizeof(ans)); memset(st, 0, sizeof(st)); memset(vis, 0, sizeof(vis)); cnt = 0; ans[cnt++] = C; vis[C] = 1; dfs(0, 0, C); sort(ans, ans+cnt); for(int i = 0; i < cnt; i++) printf("%d%c", ans[i], i == cnt-1 ? '\n' : ' '); } return 0; }