【USACO 1.4】Mother's Milk

时间:2023-03-08 23:05:09
【USACO 1.4】Mother's Milk
/*
TASK: milk3
LANG: C++
SOLVE: 倒水,dfs,枚举每一种倒法,ca[i][j]记录a和c桶的状态,因为总体积不变,故b的状态不需要记录。
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int a,b,c;
bool ca[][];
void dfs(int na,int nb,int nc){
// printf("%d %d %d\n",na,nb,nc);
if(ca[na][nc])return;
ca[na][nc]=;
dfs(max(na+nb-b,),min(b,na+nb),nc);//a->b
dfs(min(a,na+nb),max(na+nb-a,),nc);//b->a
dfs(max(na+nc-c,),nb,min(c,na+nc));//a->c
dfs(min(a,na+nc),nb,max(na+nc-a,));//c->a
dfs(na,max(nc+nb-c,),min(c,nc+nb));//b->c
dfs(na,min(nc+nb,b),max(nc+nb-b,));//c->b
}
int main(){
freopen("milk3.in","r",stdin);
freopen("milk3.out","w",stdout);
scanf("%d%d%d",&a,&b,&c);
dfs(,,c);
int ok=;
for(int i=;i<=c;i++)
if(ca[][i]){
if(ok) printf(" ");
printf("%d",i);
ok=;
}
puts("");
return ;
}