Codeforces 585D Lizard Era: Beginning | 折半搜索
2017-12-14 19:49
435 查看
参考这个博客
#include<cstdio> #include<algorithm> #include<cstring> #include<map> #include<vector> typedef long long ll; using namespace std; map< pair<int,int> , pair<int,int> > mp; map< pair<int,int> , pair<int,int> > :: iterator it; int ans=-92345678,n,a[30][4]; ll front,back; vector <int> v; void dfs1(int x,int l,int m,int w,int f) { if (x>n/2) { it=mp.find(make_pair(l-m,w-m)); if (it!=mp.end()) { if (l>it->second.first) mp[make_pair(l-m,w-m)]=make_pair(l,f); } else mp[make_pair(l-m,w-m)]=make_pair(l,f); return ; } dfs1(x+1,l+a[x][1],m+a[x][2],w,f*3+0); dfs1(x+1,l+a[x][1],m,w+a[x][3],f*3+1); dfs1(x+1,l,m+a[x][2],w+a[x][3],f*3+2); } void dfs2(int x,int l,int m,int w,int f) { if (x>n) { it=mp.find(make_pair(m-l,m-w)); if (it!=mp.end()) { if (it->second.first+l>ans) { ans=it->second.first+l; front=it->second.second; back=f; } } return ; } dfs2(x+1,l+a[x][1],m+a[x][2],w,f*3+0); dfs2(x+1,l+a[x][1],m,w+a[x][3],f*3+1); dfs2(x+1,l,m+a[x][2],w+a[x][3],f*3+2); } void print(int x) { if (!x) puts("LM"); else if (x==1) puts("LW"); else puts("MW"); } int main() { scanf("%d",&n); for (int i=1;i<=n;i++) { scanf("%d%d%d",&a[i][1],&a[i][2],&a[i][3]); } dfs1(1,0,0,0,0); dfs2(n/2+1,0,0,0,0); if (ans>-92345678) { for (int i=(n+1)/2;i>=1;i--) { v.push_back(back%3); back/=3; } for (int i=n/2;i>=1;i--) { v.push_back(front%3); front/=3; } for (int i=v.size()-1;i>=0;i--) print(v[i]); } else puts("Impossible"); return 0; }
相关文章推荐
- [codeforces] 585D Lizard Era: Beginning || 双向dfs
- CodeForces 585D Lizard Era: Beginning
- [Codeforces 585D] Lizard Era: Beginning (折半枚举)
- CodeForces 372A Counting Kangaroos is Fun袋鼠口袋问题折半搜索
- codeforces 589C Polycarp's Masterpiece(分治 折半搜索)
- codeforces 888E Maximum Subsequence (折半枚举 双向搜索)
- CodeForces 197D 搜索
- CodeForces 327 E.Axis Walking(折半枚举+map)
- CodeForces-Gym 101142C CodeCoder vs TopForces(搜索)
- Codeforces 585D Lizard Era: Beginning
- 【bzoj1770/Usaco2009 Nov】lights 燈——折半搜索
- CodeForces - 782 C Andryusha and Colored Balloons(搜索)
- 【洛谷】1466 集合 Subset Sums 折半搜索
- CodeForces 723D Lakes in Berland (dfs搜索)
- 160_折半枚举(双向搜索) 4 Values whose sum is 0 (POJ No.2785)
- codeforces888e(折半枚举+二分搜索)
- codeforces----2017 Hackatari Codeathon(A 暴力搜索 G概率)(水题DEH)
- codeforces 785 C. Anton and Fairy Tale (数学 二分搜索)
- Codeforces Round #297 (Div. 2)E. Anya and Cubes(折半搜索)
- 2014 Benelux Algorithm Programming Contest (BAPC 14) K - Key to Knowledge(折半搜索)