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

#include<iostream>
#include<fstream>
using namespace std;

const int W = 21;
int ma,mb,mc;
bool isOk[W];
bool vis[W][W];

void dfs(int a,int b){
if(vis[a][b])
return;

vis[a][b] = true;//该状态的搜索情况做上标记，以防止重复递归。

int c = mc - a - b;//当前状态下的a,b,c

if(a == 0)
isOk[c] = true;

//a->b
if(a+b<=mb)
dfs(0,a+b);
else
dfs(a-mb+b,mb);

//a->c
if(a+c<=mc)
dfs(0,b);
else
dfs(a-mc+c,b);

//b->a
if(b+a<=ma)
dfs(b+a,0);
else
dfs(ma,b-ma+a);

//b->c
if(b+c<=mc)
dfs(a,0);
else
dfs(a,b-mc+c);

//c->a
if(c+a<=ma)
dfs(c+a,b);
else
dfs(ma,b);

//c->b
if(c+b<=mb)
dfs(a,c+b);
else
dfs(a,mb);

}

int main(){
ifstream infile;
ofstream outfile;
infile.open("milk3.in");
outfile.open("milk3.out");

infile>>ma>>mb>>mc;

//memset(isOk,0,sizeof(isOk));
//memset(vis,0,sizeof(vis));
for(int i=0;i<W;i++)
{
isOk[i] = false;
for(int j=0;j<W;j++)
vis[i][j] = false;
}

dfs(0,0);

bool first = true;
for(int i=0;i<=mc;i++)
if(isOk[i]){
if(first){
outfile<<i;
first = false;
}
else
outfile<<" "<<i;
}
outfile<<endl;

return 0;
}
posted on 2012-06-04 14:53  geeker  阅读(236)  评论(1编辑  收藏  举报