http://www.luogu.org/problem/show?pid=1215
舒爽的深搜题,只有六种转移方式都搜一下就好了
因为牛奶的量一定,所以知道aa,cc就可以知道bb,所以二维即可
vis[aa][cc]判重,aa=0时令s[cc]=1,最后输出s[i]为1的i值
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a,b,c;
bool vis[25][25],s[25];
void dfs(int aa,int cc)
{if(vis[aa][cc]==1)return ;vis[aa][cc]=1;if(aa==0)s[cc]=1;int bb=c-aa-cc;if(aa!=0&&bb!=b)dfs(aa-min(aa,b-bb),cc);//a->bif(aa!=0&&cc!=c)dfs(aa-min(aa,c-cc),cc+min(aa,c-cc));//a->cif(bb!=0&&aa!=a)dfs(aa+min(bb,a-aa),cc);//b->aif(bb!=0&&cc!=c)dfs(aa,cc+min(bb,c-cc));//b->cif(cc!=0&&aa!=a)dfs(aa+min(cc,a-aa),cc-min(cc,a-aa));//c->aif(cc!=0&&bb!=b)dfs(aa,cc-min(cc,b-bb));//c->b return ;
}
int main()
{scanf("%d%d%d",&a,&b,&c);dfs(0,c); for(int i=0;i<=c;i++)if(s[i]==1)printf("%d ",i);return 0;
}