DFS
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define int long long
#define endl '\n'
using namespace std;
const int N = 25;
int A, B, C;
bool st[N][N][N];
int v[3];
void dfs(int a, int b, int c)
{
if (st[a][b][c])
{
return;
}
st[a][b][c] = true;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
int w[3] = {a, b, c};
int dv = min(w[i], v[j] - w[j]);
w[i] -= dv, w[j] += dv;
dfs(w[0], w[1], w[2]);
}
}
}
signed main(void)
{
std::ios::sync_with_stdio(false);
cin >> A >> B >> C;
v[0] = A, v[1] = B, v[2] = C;
dfs(0, 0, C);
for (int c = 0; c <= C; c++)
{
for (int b = 0; b <= B; b++)
{
if (st[0][b][c])
{
cout << c << ' ';
break;
}
}
}
cout << endl;
return 0;
}
BFS
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#define int long long
#define endl '\n'
using namespace std;
struct Node
{
int a, b, c;
};
const int N = 25;
int A, B, C;
bool st[N][N][N];
void bfs()
{
queue<Node> q;
q.push({0, 0, C});
st[0][0][C] = true;
while (q.size())
{
auto t = q.front();
q.pop();
const int v[3] = {A, B, C};
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
int w[3] = {t.a, t.b, t.c};
int dv = min(v[j] - w[j], w[i]);
w[i] -= dv, w[j] += dv;
int a = w[0], b = w[1], c = w[2];
if (!st[a][b][c])
{
st[a][b][c] = true;
q.push({a, b, c});
}
}
}
}
}
signed main(void)
{
std::ios::sync_with_stdio(false);
cin >> A >> B >> C;
bfs();
for (int c = 0; c <= C; c++)
{
for (int b = 0; b <= B; b++)
{
if (st[0][b][c])
{
cout << c << ' ';
break;
}
}
}
cout << endl;
return 0;
}