5248: [2018多省省队联测]一双木棋
2018-06-29 16:10
239 查看
5248: [2018多省省队联测]一双木棋
分析:
极大极小搜索!记忆化一下,所有的状态是阶梯状的!然后缩成一个LL。
好像状压dp也行。
考试的时候。。。啥都不会。。。不会极大极小搜索,不会dp,不会这道题!
代码:
#include<bits/stdc++.h> using namespace std; typedef long long LL; inline int read() { int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1; for (;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f; } const int N = 20; const LL base = 11; int a ,b ,sta ,n,m; map<LL,int> p; inline LL getHash() { LL ret = 0; for (int i=1; i<=n; ++i) ret = ret * base + sta[i]; return ret; } inline void getState(LL S) { for (int i=n; i>=1; --i) sta[i] = S % base,S /= base; } int Minimax(int player,LL S) { if (p.find(S) != p.end()) return p[S]; getState(S); int res = player ? 1e9 : -1e9; for (int i=1; i<=n; ++i) { if (sta[i-1] > sta[i]) { ++ sta[i]; LL T = getHash(); if (!player) res = max(res,Minimax(player^1,T) + a[i][sta[i]]) ; else res = min(res,Minimax(player^1,T) - b[i][sta[i]]) ; -- sta[i]; } } p[S] = res; return res; } int main() { n = read(),m = read(); for (int i=1; i<=n; ++i) for (int j=1; j<=m; ++j) a[i][j] = read(); for (int i=1; i<=n; ++i) for (int j=1; j<=m; ++j) b[i][j] = read(); for (int i=1; i<=n; ++i) sta[i] = m; p[getHash()] = 0; sta[0] = m; cout << Minimax(0,0); return 0; }
相关文章推荐
- bzoj 5248: [2018多省省队联测]一双木棋
- bzoj5248: [2018多省省队联测]一双木棋
- [BZOJ5248][九省联考2018]一双木棋(连通性DP,对抗搜索)
- BZOJ.5248.[九省联考2018]一双木棋chess(对抗搜索 记忆化)
- [BZOJ5248] 2018九省联考 D1T1 一双木棋 | 博弈论 状压DP
- [九省联考 2018]一双木棋chess
- 【BZOJ5248】【九省联考2018】一双木棋(搜索,哈希)
- [BZOJ5248][多省联测2018]双木棋chess
- [九省联考2018] 一双木棋 chess
- BZOJ5248:[九省联考2018]一双木棋——题解
- 洛谷P4363 [九省联考2018]一双木棋chess 【状压dp】
- js-添加一双眼睛
- 考上MBA,为自己装一双翅膀
- 借我一双慧眼-------辨别财务造假
- js+css3实现一双转动的眼睛-------Day68
- 百度之星2015初赛(1)1003 HDOJ5248 序列变换(二分 贪心)
- 天空中的云一双翅膀的努力
- 因为一双鞋,阿里程序员相亲被拒
- 感谢买灌饼的阿姨给我一个电饭锅,下午到超市卖了两件衬衫及一双皮鞋.
- 一双高跟鞋