計蒜客——無腦博士的試管們

5 6 7 8 9 10

``````#include <iostream>
#include <cstdio>
#include <set>

unsigned int A, B, C;

std::set<unsigned int> fin;
const unsigned int num = 25;
bool flag[num][num][num] = {false};

void DFS(unsigned int a, unsigned int b, unsigned int c);
int main()
{
scanf("%d %d %d", &A, &B, &C);
DFS(0, 0, C);
for (std::set<unsigned int>::iterator it = fin.begin(); it != --fin.end(); ++it)
std::cout << *it << " ";
std::cout << *(--fin.end());
return 0;
}

bool can(unsigned int x, unsigned int y, unsigned int X, unsigned int Y, int * temp) {
if (x == 0 || y == Y) return false;
if (Y - y >= x) {
y += x;
x = 0;
}
else {
x -= Y - y;
y = Y;
}
temp[0] = x;
temp[1] = y;
return true;
}

void DFS(unsigned int a, unsigned int b, unsigned int c) {
if (flag[a][b][c]) return;
if (a == 0) fin.insert(c);
flag[a][b][c] = true;

int temp[2];
// a -> b
if (can(a, b, A, B, temp)) DFS(temp[0], temp[1], c);
// a -> c
if (can(a, c, A, C, temp)) DFS(temp[0], b, temp[1]);
// b -> a
if (can(b, a, B, A, temp)) DFS(temp[1], temp[0], c);
// b -> c
if (can(b, c, B, C, temp)) DFS(a, temp[0], temp[1]);
// c -> a
if (can(c, a, C, A, temp)) DFS(temp[1], b, temp[0]);
// c -> b
if (can(c, b, C, B, temp)) DFS(c, temp[1], temp[0]);
}

``````