/*
ID: cm750621
PROG: milk3
LANG: C++
*/
#include<stdio.h>
#include<stdlib.h>
int a,b,c,ans[500],n;
short may[30][30][30];
int dfs(int a1,int b1,int c1){
if(may[a1][b1][c1])
return 0;
if(a1+b1+c1!=c){
printf("Error");
return 1;
}
if(a1==0){
ans[++n]=c1;
}
may[a1][b1][c1]=1;
if(c1>=a-a1)
dfs(a,b1,c1-a+a1);
else
dfs(a1+c1,b1,0);
if(c1>=b-b1)
dfs(a1,b,c1-b+b1);
else
dfs(a1,b1+c1,0);
if(a1>=b-b1)
dfs(a1-b+b1,b,c1);
else
dfs(0,a1+b1,c1);
dfs(0,b1,c1+a1);
if(b1>a-a1)
dfs(a,b1-a+a1,c1);
else
dfs(a1+b1,0,c1);
dfs(a1,0,c1+b1);
return 0;
}
int main(){
freopen("milk3.in","r",stdin);
freopen("milk3.out","w",stdout);
int i,j,k,m,maxj,tmp;
scanf("%d%d%d",&a,&b,&c);
dfs(0,0,c);
for(i=1;i<=n;i++){
maxj=i;
for(j=i+1;j<=n;j++){
if(ans[j]<ans[maxj])
maxj=j;
}
tmp=ans[maxj];
ans[maxj]=ans[i];
ans[i]=tmp;
}
for(i=1;i<n;i++){
printf("%d ",ans[i]);
}
printf("%d\n",ans[n]);
return 0;
}
usaco 1.4.2 milk3
最新推荐文章于 2017-06-10 22:40:01 发布