简单的dfs题。两两倒牛奶部分写的比较繁琐。。。用循环比较好
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("milk3.in");
ofstream fout("milk3.out");
#ifdef _DEBUG
#define out cout
#define in cin
#else
#define out fout
#define in fin
#endif
bool mark[21][21][21];
int cap[3];
bool result[21];
void dfs(int ma,int mb,int mc);
void solve()
{
in>>cap[0]>>cap[1]>>cap[2];
memset(mark,0,sizeof(mark));
memset(result,0,sizeof(result));
dfs(0,0,cap[2]);
bool first = true;
for(int i=0;i<=20;++i){
if(result[i]){
if(first){
out<<i;
first = false;
}else{
out<<" "<<i;
}
}
}
out<<endl;
}
void dfs(int ma,int mb,int mc)
{
if(mark[ma][mb][mc])
return;
mark[ma][mb][mc]=true;
if(ma==0){
result[mc]=true;
}
int trans;
//a->b
trans = min(ma,cap[1]-mb);
dfs(ma-trans,mb+trans,mc);
//a->c
trans = min(ma,cap[2]-mc);
dfs(ma-trans,mb,mc+trans);
//b->a
trans = min(mb,cap[0]-ma);
dfs(ma+trans,mb-trans,mc);
//b->c
trans = min(mb,cap[2]-mc);
dfs(ma,mb-trans,mc+trans);
//c->a
trans = min(mc,cap[0]-ma);
dfs(ma+trans,mb,mc-trans);
//c->b
trans = min(mc,cap[1]-mb);
dfs(ma,mb+trans,mc-trans);
}
int main(int argc,char *argv[])
{
solve();
return 0;
}