B5248 [2018多省省队联测]一双木棋 状压dp
这个题当时划水,得了二十分,现在来整一整。
这个题用状压来压缩边界线,然后通过记忆化搜索进行dp。我们可以观察到,其实每次转移,就是把一个1向左移一位。最后的状态设为0。
这其中还要有一个变量来记录谁下棋,用maxmin算法,其实就是一步取max,下一步取min,然后就木有了。
ps:a-b剪枝没学,日后再学吧。
题干:
Description
Input
Output
Sample Input
2 7 3
9 1 2
3 7 2
2 3 1
Sample Output
HINT

Source
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(int i = a;i <= n;i++)
#define lv(i,a,n) for(int i = a;i >= n;i--)
#define clean(a) memset(a,0,sizeof(a))
const int INF = 1e9 + ;
typedef long long ll;
typedef double db;
template <class T>
void read(T &x)
{
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
}
int n,m;
int a[][],b[][];
int f[ << ( << )];
int dfs(int sta,bool who,int n,int m)
{
if(~f[sta])
return f[sta];
f[sta] = who ? -INF : INF;
int x = n,y = ;
duke(i,,n + m - )
{
if(sta >> i & )
x--;
else
y++;
if((sta >> i & ) != )
continue;
int nxt = sta ^ ( << i);
if(who)
{
f[sta] = max(f[sta],dfs(nxt,who ^ ,n,m) + a[x][y]);
}
else
{
f[sta] = min(f[sta],dfs(nxt,who ^ ,n,m) - b[x][y]);
}
}
return f[sta];
}
int main()
{
read(n);read(m);
duke(i,,n - )
{
duke(j,,m - )
{
read(a[i][j]);
}
}
duke(i,,n - )
{
duke(j,,m - )
{
read(b[i][j]);
}
}
memset(f,0xff,sizeof(f));
f[(( << n) - ) << m] = ;
printf("%d\n",dfs(( << n) - ,,n,m));
return ;
}
B5248 [2018多省省队联测]一双木棋 状压dp的更多相关文章
- bzoj 5248: [2018多省省队联测]一双木棋
Description 菲菲和牛牛在一块n行m列的棋盘上下棋,菲菲执黑棋先手,牛牛执白棋后手.棋局开始时,棋盘上没有任何棋子, 两人轮流在格子上落子,直到填满棋盘时结束.落子的规则是:一个格子可以落子 ...
- bzoj5248 [2018多省省队联测]一双木棋
直接hash+爆搜即可. #include <cstdio> #include <cstring> #include <iostream> #include < ...
- bzoj千题计划307:bzoj5248: [2018多省省队联测]一双木棋
https://www.lydsy.com/JudgeOnline/problem.php?id=5248 先手希望先手得分减后手得分最大,后手希望先手得分减后手得分最小 棋盘的局面一定是阶梯状,且从 ...
- BZOJ 5248: [2018多省省队联测]一双木棋(对抗搜索)
Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 439 Solved: 379[Submit][Status][Discuss] Descriptio ...
- 【刷题】BZOJ 5248 [2018多省省队联测]一双木棋
Description 菲菲和牛牛在一块n行m列的棋盘上下棋,菲菲执黑棋先手,牛牛执白棋后手.棋局开始时,棋盘上没有任何棋子, 两人轮流在格子上落子,直到填满棋盘时结束.落子的规则是:一个格子可以落子 ...
- [BZOJ5248] 2018九省联考 D1T1 一双木棋 | 博弈论 状压DP
题面 菲菲和牛牛在一块\(n\)行\(m\)列的棋盘上下棋,菲菲执黑棋先手,牛牛执白棋后手. 棋局开始时,棋盘上没有任何棋子,两人轮流在格子上落子,直到填满棋盘时结束. 落子的规则是:一个格子可以落子 ...
- 2018.07.18 洛谷P1171 售货员的难题(状压dp)
传送门 感觉是一道经典的状压dp,随便写了一发卡了卡常数开了个O(2)" role="presentation" style="position: relati ...
- [BZOJ5248][九省联考2018]一双木棋(连通性DP,对抗搜索)
5248: [2018多省省队联测]一双木棋 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 43 Solved: 34[Submit][Status ...
- BZOJ_5249_Luogu_P4364_[2018多省省队联测]_IIIDX_九省联考2018_JLOI2018_线段树
BZOJ_5249_[2018多省省队联测]IIIDX_线段树 Description [题目背景] Osu听过没?那是Konano最喜欢的一款音乐游戏,而他的梦想就是有一天自己也能做个独特酷炫的音乐 ...
随机推荐
- JS——stye属性
1.样式少的时候使用 this.parentNode.style.backgroundColor="yellow"; 2.style是对象 console.log(box.styl ...
- [Windows Server 2012] WordPress安全设置方法
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:WordP ...
- mysql有关时间是问题
mysql中有关时间的类型 date/datetime/time/timestamp/year date:表示日期的类型,格式为:“yyyy-MM-dd” dateTime:表示日期时间的类型,格式 ...
- ES6 作用域的问题
- IO文件读取
/** *按字节读取文件 */@Testpublic void readerByte() { File file = new File("D:\\BindCheckControllerTes ...
- MHA的MySQL高可用方案实战
功能: 1)master的故障切换(keepalived VIP的飘移) 2)主从复制角色的提升和重新转向 其中master 对外提供写服务,备选master2(实际的slave提供读服务,slave ...
- (C/C++学习)11.随机数组的快速查找
说明:利用随机函数生成一个随机数组,然后对数组进行排列,再利用二分查找快速查找一个数. 一.生成随机数组 time_t ts; //等价于long ts; unsigned int num = tim ...
- CentOS7.2下安装php加速软件Xcache
说明: php安装目录:/usr/local/php php.ini配置文件路径:/usr/local/php/etc/php.ini Nginx安装目录:/usr/local/nginx Nginx ...
- Git使用笔记 (github为例)
---`Git`# Git管理 #- 创建仓库 git init 在本地目录下建立新git仓库,该仓库可以为空也可以是重新初始化的仓库.该命令将创建一个名为 .git 的子目录,这个子目录含有初始化的 ...
- HDU 5446 Unknown Treasure
Unknown Treasure Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...