1355. 母亲的牛奶

经典问题,直接暴搜出所有方案即可。

const int N=25;
bool vis[N][N][N];
int a,b,c;
vector<int> ans;

void dfs(int x,int y,int z)
{
    if(vis[x][y][z]) return;
    vis[x][y][z]=true;

    if(x == 0) ans.pb(z);

    int t;
    t=min(x,b-y);
    dfs(x-t,y+t,z);
    t=min(x,c-z);
    dfs(x-t,y,z+t);

    t=min(y,a-x);
    dfs(x+t,y-t,z);
    t=min(y,c-z);
    dfs(x,y-t,z+t);

    t=min(z,a-x);
    dfs(x+t,y,z-t);
    t=min(z,b-y);
    dfs(x,y+t,z-t);
}

int main()
{
    cin>>a>>b>>c;

    dfs(0,0,c);

    sort(ans.begin(),ans.end());
    for(int i=0;i<ans.size();i++)
        if(i) cout<<' '<<ans[i];
        else cout<<ans[i];
    cout<<endl;
    //system("pause");
    return 0;
}
posted @ 2021-05-25 09:36  Dazzling!  阅读(24)  评论(0编辑  收藏  举报