/* 
    ID:chenjiong
    PROG:milk3
    LANG:C++
*/

#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

int bucket[3];
int amount[3];
int ans[20];
int num;

bool vis_2[21];
bool vis[21][21][21];

int order[6][2] = {{2,1},{2,0},{1,0},{1,2},{0,1},{0,2}};

bool is_empty(int No)
{
    if ( amount[No] == 0 )
        return true;
    return false;
}

bool is_full(int No)
{
    if ( bucket[No] == amount[No] )
        return true;
    return false;
}

void dfs()
{
    if ( vis[amount[0]][amount[1]][amount[2]] )
        return;
    if ( is_empty(0) && vis_2[amount[2]] == false )
    {
        vis_2[amount[2]] = true;
        ans[num++] = amount[2];
    }
    
    for (int i = 0; i < 6; i++)
    {
        vis[amount[0]][amount[1]][amount[2]] = true;
        int x = order[i][0];
        int y = order[i][1];
        if ( is_empty(x) || is_full(y) )
            continue;
        int rest = bucket[y] - amount[y];
        int tmp = amount[x] < rest ? amount[x] : rest;
        amount[x] -= tmp;
        amount[y] += tmp;    
        dfs();
        amount[x] += tmp;
        amount[y] -= tmp;
    }
    
}

int main()
{
    freopen("milk3.in","r",stdin);
    freopen("milk3.out","w",stdout);
    
    int i;
    for ( i = 0; i < 3; i++)
        scanf("%d",&bucket[i]);

    amount[0] = amount[1] = 0;
    amount[2] = bucket[2];

    memset(vis,0,sizeof(vis));
    dfs();

    sort(ans,ans + num);

    for ( i = 0; i < num - 1; i++)
        printf("%d ",ans[i]);
    printf("%d\n",ans[num - 1]);

    return 0;
}

 

posted on 2012-10-18 22:40  Sinker  阅读(143)  评论(0编辑  收藏  举报