您的位置:首页 > 其它

【USACO】Mother's Milk(搜索)

2015-04-14 13:18 411 查看
一开始还在想去重的问题,结果发现后台数据貌似没有重复的情况= =

/*
ID: 18906421
LANG: C++
PROG: milk3
*/
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn = 25;
int vis[maxn][maxn][maxn] = {0};
vector<int>ans;
int cnt = 0,aa,bb,cc;
int move_to(int V,int v1,int v2){ //v1 -> v2
    int left = V - v2;
    if(v1 > left)
        return left;
    else
        return v1;
}
void dfs(int a,int b,int c){
    if(vis[a][b][c]) return;
    vis[a][b][c] = 1;
    if(a == 0) ans.push_back(c);
    int d;
    //a -> b
    d = move_to(bb,a,b);
    dfs(a - d,b + d,c);
    //a -> c
    d = move_to(cc,a,c);
    dfs(a - d,b,c + d);
    //b -> a
    d = move_to(aa,b,a);
    dfs(a + d,b - d,c);
    //b -> c
    d = move_to(cc,b,c);
    dfs(a,b - d,c + d);
    //c -> a
    d = move_to(aa,c,a);
    dfs(a + d,b,c - d);
    //c -> b
    d = move_to(bb,c,b);
    dfs(a,b + d,c - d);
    return;
}
int main(){
    freopen("milk3.in","r",stdin);
    freopen("milk3.out","w",stdout);
    scanf("%d%d%d",&aa,&bb,&cc);
    dfs(0,0,cc);
    sort(ans.begin(),ans.end());
    for(int i = 0; i < ans.size(); i++){
        if(i)
            printf(" ");
        printf("%d",ans[i]);
    }
    puts("");
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: