Posted on 2009-03-21 19:34
superman 阅读(130)
评论(0) 编辑 收藏 引用 所属分类:
USACO
1 #include <queue>
2 #include <iostream>
3
4 using namespace std;
5
6 int A, B, C;
7
8 bool x[25][25][25];
9
10 void search(int a, int b, int c)
11 {
12 if (x[a][b][c] == true)
13 return;
14
15 x[a][b][c] = true;
16
17 if (a)
18 {
19 search(a - min(a, B - b), b + min(a, B - b), c);
20 search(a - min(a, C - c), b, c + min(a, C - c));
21 }
22 if (b)
23 {
24 search(a + min(b, A - a), b - min(b, A - a), c);
25 search(a, b - min(b, C - c), c + min(b, C - c));
26 }
27 if (c)
28 {
29 search(a + min(c, A - a), b, c - min(c, A - a));
30 search(a, b + min(c, B - b), c - min(c, B - b));
31 }
32 }
33
34 int main()
35 {
36 freopen("milk3.in", "r", stdin);
37 freopen("milk3.out", "w", stdout);
38
39 cin >> A >> B >> C;
40
41 search(0, 0, C);
42
43 queue <int> q;
44 for (int b = B; b >= 0; b--)
45 if (x[0][b][C - b])
46 q.push(C - b);
47
48 while (q.empty() == false)
49 {
50 cout << q.front() << (q.size() == 1 ? '\n' : ' ');
51 q.pop();
52 }
53
54 return 0;
55 }
56