标签:
一开始还在想去重的问题,结果发现后台数据貌似没有重复的情况= =
/* 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; }
标签:
原文地址:http://blog.csdn.net/u013451221/article/details/45040689