【USACO】Mother's Milk(搜索)

一开始还在想去重的问题,结果发现后台数据貌似没有重复的情况= =

/*
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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值