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\) 首曲目 ...
随机推荐
- Node服务端极速搭建 -- nvmhome
> 本文意在让你掌握极速搭建Node服务端(任何Project) ```$ whoaminame: kelvinemail: kelvv@outlook.comhomepage: www.kel ...
- Python3 中日语料分句实现
0. 背景 因为最近在看平行语料句对齐.词对齐的缘故,想做对齐的话需要先做一个分句. 一开始利用正则和引号开关标志写了一种方法,中间想到一个小技巧,写出来比较简单通用,想把这一小段代码分享一下. 1. ...
- css3圆形光环闪烁效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- queue_monitor
red_4 droptail_4
- 爬虫IP被禁的简单解决方法——切换UserAgent
[转载]Python爬虫之UserAgent 用到的库 https://github.com/hellysmile/fake-useragent
- Bootstrap 4/3 页面基础模板 与 兼容旧版本浏览器
Bootstrap 3 与 4 差别很大,目录文件结构.所引入的内容也不同,这里说说一下 Bootstrap 引入的文件.网页模板和兼容性问题.本网站刚刚搭建好,正好发一下文章原来测试网站. Boot ...
- August 22nd 2017 Week 34th Tuesday
Stop trying to find a rewind. It's life, not a movie. 别妄想倒带,这是生活,不是电影. There is no need to go back t ...
- Reporting Service编程----访问Web服务
将报表服务器 Web 服务的引用添加到项目中后,下一步是创建 Web 服务代理类的实例. 然后,您可以通过调用代理类中的方法来访问 Web 服务的方法. 当你的应用程序调用这些方法时,代理类生成的代码 ...
- Apache Spark : RDD
Resilient Distributed Datasets Resilient Distributed Datasets (RDD) is a fundamental data structure ...
- 我的第一个 Servlet
简单记录一下我从头写一个 Servlet 的过程. 我安装的是 Tomcat 7 版本,在 Ubuntu 18.04 上运行,IDE 为 Intellij IDEA. 首先创建一个 Java Web ...