BZOJ 5248: [2018多省省队联测]一双木棋(对抗搜索)
Time Limit: 20 Sec Memory Limit: 512 MB
Submit: 439 Solved: 379
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
2 7 3
9 1 2
3 7 2
2 3 1
Sample Output
HINT

Source
用$now[i]$表示第$i$行已经放了$now[i]$个棋子
爆搜之后发现状态数很小
因此用map记忆化一下就好
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define LL long long
using namespace std;
using namespace __gnu_pbds;
const int MAXN = , INF = 1e9 + , base = ;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int N, M;
int A[MAXN][MAXN], B[MAXN][MAXN];
cc_hash_table<LL, int>mp;
int now[MAXN];
LL gethash() {
LL x = ;
for(int i = ; i <= N; i++) x = x * base + now[i];
return x;
}
void push(LL x) {
for(int i = N; i >= ; i--) now[i] = x % base, x /= base;
}
int getnext() {
int x = ;
for(int i = ; i <= N; i++) x += now[i];
return x & ;
}
int dfs(LL sta) {
if(mp.find(sta) != mp.end()) return mp[sta];
push(sta);
bool type = getnext();
int ans = !type ? -INF : INF;
for(int i = ; i <= N; i++) {
if(now[i] < now[i - ]) {
now[i]++;
LL nxt = gethash();
int val = dfs(nxt);
ans = !type ? max(ans, val + A[i][now[i]]) : min(ans, val - B[i][now[i]]);
now[i]--;
}
}
return mp[sta] = ans;
}
main() {
#ifdef WIN32
freopen("a.in", "r", stdin);
//freopen("a.out", "w", stdout);
#else
freopen("chess2018.in", "r", stdin);
freopen("chess2018.out", "w", stdout);
#endif
N = read(); M = read();
for(int i = ; i <= N; i++)
for(int j = ; j <= M; j++)
A[i][j] = read();
for(int i = ; i <= N; i++)
for(int j = ; j <= M; j++)
B[i][j] = read();
for(int i = ; i <= N; i++) now[i] = M;
mp[gethash()] = ;
dfs();
printf("%d", mp[]);
}
BZOJ 5248: [2018多省省队联测]一双木棋(对抗搜索)的更多相关文章
- bzoj 5248: [2018多省省队联测]一双木棋
Description 菲菲和牛牛在一块n行m列的棋盘上下棋,菲菲执黑棋先手,牛牛执白棋后手.棋局开始时,棋盘上没有任何棋子, 两人轮流在格子上落子,直到填满棋盘时结束.落子的规则是:一个格子可以落子 ...
- 【刷题】BZOJ 5248 [2018多省省队联测]一双木棋
Description 菲菲和牛牛在一块n行m列的棋盘上下棋,菲菲执黑棋先手,牛牛执白棋后手.棋局开始时,棋盘上没有任何棋子, 两人轮流在格子上落子,直到填满棋盘时结束.落子的规则是:一个格子可以落子 ...
- bzoj千题计划307:bzoj5248: [2018多省省队联测]一双木棋
https://www.lydsy.com/JudgeOnline/problem.php?id=5248 先手希望先手得分减后手得分最大,后手希望先手得分减后手得分最小 棋盘的局面一定是阶梯状,且从 ...
- bzoj5248 [2018多省省队联测]一双木棋
直接hash+爆搜即可. #include <cstdio> #include <cstring> #include <iostream> #include < ...
- B5248 [2018多省省队联测]一双木棋 状压dp
这个题当时划水,得了二十分,现在来整一整. 这个题用状压来压缩边界线,然后通过记忆化搜索进行dp.我们可以观察到,其实每次转移,就是把一个1向左移一位.最后的状态设为0. 这其中还要有一个变量来记录谁 ...
- bzoj 5249 [2018多省省队联测] IIIDX
bzoj 5249 [2018多省省队联测] IIIDX Link Solution 首先想到贪心,直接按照从大到小的顺序在后序遍历上一个个填 但是这样会有大问题,就是有相同的数的时候,会使答案不优 ...
- 【BZOJ5248】【九省联考2018】一双木棋(搜索,哈希)
[BZOJ5248][九省联考2018]一双木棋(搜索,哈希) 题面 BZOJ Description 菲菲和牛牛在一块n行m列的棋盘上下棋,菲菲执黑棋先手,牛牛执白棋后手.棋局开始时,棋盘上没有任何 ...
- bzoj 5251: [2018多省省队联测]劈配
Description 一年一度的综艺节目<中国新代码>又开始了. Zayid从小就梦想成为一名程序员,他觉得这是一个展示自己的舞台,于是他毫不犹豫地报名了. 题目描述 轻车熟路的Zayi ...
- BZOJ 5249: [2018多省省队联测]IIIDX(贪心 + 线段树)
题意 这一天,\(\mathrm{Konano}\) 接到了一个任务,他需要给正在制作中的游戏 \(\mathrm{<IIIDX>}\) 安排曲目 的解锁顺序.游戏内共有\(n\) 首曲目 ...
随机推荐
- Web Api ——创建WebAPI
方法在Win10 + VS2017(MVC5)测试通过 1.建立 WebApi项目: 选择菜单 “文件->新建醒目->web ->ASP.NET Web 应用程序” 输入项目名称和位 ...
- spring cloud zuul 配置
参考:http://www.ityouknow.com/springcloud/2017/06/01/gateway-service-zuul.html spring boot版本:2.0.3.REL ...
- python之复数
#coding=utf8 ''''' 复数是由一个实数和一个虚数组合构成,表示为:x+yj 一个负数时一对有序浮点数(x,y),其中x是实数部分,y是虚数部分. Python语言中有关负数的概念: 1 ...
- c# winfrom 皮肤切换 控件 IrisSkin2.dll 使用
在c#应用程序中使用IrisSkin2.dll美化界面 IrisSkin2.dll 下载地址:http://d.download.csdn.net/down/1694982/sgear 一.添加控件I ...
- 深入浅出SharePoint——获取Choice Field的Mapping value
list field对应的caml定义如下 <Field Type="Choice" DisplayName="Inspection Result" Re ...
- December 30th 2016 Week 53rd Friday
Life without love is like a tree without blossoms or fruit. 缺少爱的生活就像从未开花结果的枯树. Love is not only the ...
- [EffectiveC++]item23:Prefer non-member non-friend functions to member functions
99页 导致较大封装性的是non-member non-friend函数,因为它并不增加“能否访问class内之private成分”的函数数量.
- python_4程序设计基础
1注释 2变量和常量 3命名 4表达式 5赋值语句
- centos6.4 minimal 安装kvm
操作系统是网易源下载的centos 64位的minimal安装包,很多工具都没有,像gcc make wget which where 等统统没有,好在有yum 这里为了简单起见直接用yum安装kvm ...
- Java的Stream流
yi.控制台输入输出流, 1.读取控制台输入 Java的控制台输入由System.in完成.为了获得一个绑定到控制台的字符流,可以把System.in包装在一个BufferedReader对象中来创建 ...