您的位置:首页 > 其它

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;
}

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: