Codeforces Round #459 (Div. 2):D. MADMAX(记忆化搜索+博弈论)
题意
在一个有向无环图上,两个人分别从一个点出发,两人轮流从当前点沿着某条边移动,要求经过的边权不小于上一轮对方经过的边权(ASCII码),如果一方不能移动,则判负。两人都采取最优策略,求两人分别从每个点出发的胜负关系表。
分析
记忆化搜索。
f[x][y][v]表示现在两人分别在x,y,上一轮经过的边权为v时x是否能胜利(胜利为1,失败为0)。
考虑如何转移:
对于一条从x到u的边权为val的边,如果val>=v,则可以走这条边,算出f[y][u][val],
如果f[y][u][val]为0,则说明在 f[x][y][v]这个状态下,有使得x胜利的方案,因为两个玩家都采取最优策略,这时x必定获胜。f[x][y][v]=1
如果f[y][u][val]为1,不要紧,主动权现在在处于x点的玩家手中,他可以不从这条路走,继续考察下一条x的出边。
如果无论如何处于x的玩家都赢不了,那么f[x][y][v]=0。
巧妙地博弈
代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n,m;
int u,v;
char s[4];
int dp[101][101][30];//dp[u][v][x]当前两人在u,v且上一轮边权为x时u的胜负
vector<pair<int,int> >mp[101];
int dfs(int u,int v,int x)
{
if(~dp[u][v][x]) return dp[u][v][x];
dp[u][v][x]=0;
int sz=mp[u].size();
for(int i=0;i<sz;++i)
{
pair<int,int>tmp=mp[u][i];
if(tmp.second>=x&&(!dfs(v,tmp.first,tmp.second))) {dp[u][v][x]=1;break;}
}
return dp[u][v][x];
}
int main(int argc, char const *argv[])
{
scanf("%d %d",&n,&m);
for(int i=1;i<=m;++i)
{
scanf("%d %d %s",&u,&v,s);
mp[u].push_back(make_pair(v,s[0]-'a'));
}
memset(dp,-1,sizeof(dp));
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j)
if(dfs(i,j,0)) putchar('A');
else putchar('B');
puts("");
}
return 0;
}
Codeforces Round #459 (Div. 2):D. MADMAX(记忆化搜索+博弈论)的更多相关文章
- Codeforces Round #336 (Div. 2) D. Zuma 记忆化搜索
D. Zuma 题目连接: http://www.codeforces.com/contest/608/problem/D Description Genos recently installed t ...
- Codeforces Round #406 (Div. 1) A. Berzerk 记忆化搜索
A. Berzerk 题目连接: http://codeforces.com/contest/786/problem/A Description Rick and Morty are playing ...
- Codeforces Round #554 (Div. 2) D 贪心 + 记忆化搜索
https://codeforces.com/contest/1152/problem/D 题意 给你一个n代表合法括号序列的长度一半,一颗有所有合法括号序列构成的字典树上,选择最大的边集,边集的边没 ...
- Codeforces Round #459 (Div. 2) D. MADMAX DFS+博弈
D. MADMAX time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...
- Codeforces Round #459 (Div. 2):D. MADMAX(记忆化搜索+博弈论)
D. MADMAX time limit per test1 second memory limit per test256 megabytes Problem Description As we a ...
- Codeforces Round #459 (Div. 2)
A. Eleven time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...
- codeforces 793 D. Presents in Bankopolis(记忆化搜索)
题目链接:http://codeforces.com/contest/793/problem/D 题意:给出n个点m条边选择k个点,要求k个点是联通的而且不成环,而且选的边不能包含选过的边不能包含以前 ...
- 牛客假日团队赛5 F 随机数 BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数 (dfs记忆化搜索的数位DP)
链接:https://ac.nowcoder.com/acm/contest/984/F 来源:牛客网 随机数 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...
- Codeforces Gym 191033 E. Explosion Exploit (记忆化搜索+状压)
E. Explosion Exploit time limit per test 2.0 s memory limit per test 256 MB input standard input out ...
随机推荐
- freetype下载和配置
一 下载编译freetype库 1 下载 地址:http://www.freetype.org/ 得到压缩文件:freetype-2.5.3.tar.gz 2 解压: 直接解压,得到文件夹freety ...
- git版本控制-- Windows+Git+TortoiseGit+COPSSH安装图文教程
Windows+Git+TortoiseGit+COPSSH 安装图文教程 教程网址: http://www.liaoxuefeng.com/wiki/0013739516305929606dd183 ...
- 【Leetcode-easy】Remove Nth Node From End of List
思路1:设置两个指针p1,p2指向表头,p1先走n步.再两个指针同时走.当p1指针指到链表尾部时,P2指针已经在需要删除节点的前一位.一定要注意一些细节. class ListNode { int v ...
- spring-boot-starter-parent
在官方文档的第三部分的13块讲述了引用的管理,官方推荐的是使用Maven和Gradle. 我一直在用的是maven,而且使用maven有些优势–spring-boot-starter-parent,这 ...
- 简单通俗解释内外网IP与端口映射
IP:分为外网IP和内网IP 也就是我们说的外网IP属于实体IP 实体IP,它是独一无二的,在网络的世界里,每一部计算机的都有他的位置,一个 IP 就好似一个门牌!例如,你要去百度的网站的话,就要去『 ...
- dotnet core on Linux 环境搭建及入门demo
首先感谢张善友大大提供的腾讯云实验室链接(https://www.qcloud.com/developer/labs/list). 以下是整个搭建过程及简单demo实例 1.搭建 .NET Core ...
- 分享知识-快乐自己:Struts2 - result标签的name属性和type属性
1):result的name属性 例如:<result name="success">/pages/success.jsp</result> Strut ...
- 一些rtsp实现的开源代码
* live.com C/S C++ http://www.live555.com * darwin S C++ http://www.opensource.a ...
- Servlet_03_部署描述符
二.参考文档 1.Servlet 3.0 之 部署描述符 2.web.xml配置详解 部署描述符文件
- 'QObject& QObject::operator=(const QObject&)' is private——无法将自定义的QObject子类放入Qt容器(container)中
先贴出问题的代码: #include<QCoreApplication> classMyObject:publicQObject { public: MyObject(QObject*pa ...