(x,y,z)可能会被多次搜索,导致该函数无限递归
by felix_tyf_s @ 2021-05-02 21:40:22
改好了
源代码:
```cpp
#include<bits/stdc++.h>
using namespace std;
int A,B,C;
bool ans[50];
int used[25][25][25];
void dfs(int x,int y,int z) {
if (used[x][y][z] == 1) {
return ;
}
if (x==0) {
ans[z] = 1; //可以将ans[]当作一个桶,这样便不用排序了
}
used[x][y][z] = 1;
int t = min(A - x, y);
dfs(x + t, y - t, z);
t = min(B - y, x);
dfs(x - t, y + t, z);
t = min(A - x, z);
dfs(x + t, y, z - t);
t = min(C - z, x);
dfs(x - t, y, z + t);
t = min(B - y, z);
dfs(x, y + t, z - t);
t = min(C - z, y);
dfs(x, y - t, z + t);//其实没必要各自判断三桶是否有牛奶
used[x][y][z] = 0;
}
int main() {
cin>>A>>B>>C;
dfs(0,0,C);
for(int i=0; i<50; i++) if(ans[i] == 1) cout << i << ' ';
return 0;
}
```
[Accepted评测记录](https://www.luogu.com.cn/record/53168674)
by SengRiy @ 2021-07-15 08:25:29