原文链接:https://www.luogu.com.cn/problem/P1215
AC代码:
#include<iostream>
#include<string.h>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
int a,b,c,visit[25][25][25];
set<int> se;
void dfs(int x,int y,int z){
int i,j;//cout<<x<<" "<<y<<" "<<z<<endl;
visit[x][y][z]=1;
if(x==0){
se.insert(z);
}
if(z>0){
if(y<b&&visit[x][y+((b-y)>z?z:(b-y))][z-((b-y)>z?z:(b-y))]==0){
dfs(x,y+((b-y)>z?z:(b-y)),z-((b-y)>z?z:(b-y)));
}
if(x<a&&visit[x+((a-x)>z?z:(a-x))][y][z-((a-x)>z?z:(a-x))]==0){
dfs(x+((a-x)>z?z:(a-x)),y,z-((a-x)>z?z:(a-x)));
}
}
if(y>0){
if(z<c&&visit[x][y-(y>(c-z)?(c-z):y)][z+(y>(c-z)?(c-z):y)]==0){
dfs(x,y-(y>(c-z)?(c-z):y),z+(y>(c-z)?(c-z):y));
}
if(x<a&&visit[x+(y>(a-x)?(a-x):y)][y-(y>(a-x)?(a-x):y)][z]==0){
dfs(x+(y>(a-x)?(a-x):y),y-(y>(a-x)?(a-x):y),z);
}
}
if(x>0){
if(y<b&&visit[x-(x>(b-y)?(b-y):x)][y+(x>(b-y)?(b-y):x)][z]==0){
dfs(x-(x>(b-y)?(b-y):x),y+(x>(b-y)?(b-y):x),z);
}
if(z<c&&visit[x-(x>(c-z)?(c-z):x)][y][z+(x>(c-z)?(c-z):x)]==0){
dfs(x-(x>(c-z)?(c-z):x),y,z+(x>(c-z)?(c-z):x));
}
}
}
int main(){
int i,j;
cin>>a>>b>>c;
memset(visit,0,sizeof(visit));
dfs(0,0,c);
for(set<int>::iterator it=se.begin();it!=se.end();it++){
cout<<*it<<" ";
}
return 0;
}