博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #459 (Div. 2) D. MADMAX DFS+博弈
阅读量:5787 次
发布时间:2019-06-18

本文共 3916 字,大约阅读时间需要 13 分钟。

D. MADMAX
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that she's not the best at games. The game is played on a directed acyclic graph (a DAG) with n vertices and m edges. There's a character written on each edge, a lowercase English letter.

Max and Lucas are playing the game. Max goes first, then Lucas, then Max again and so on. Each player has a marble, initially located at some vertex. Each player in his/her turn should move his/her marble along some edge (a player can move the marble from vertex v to vertex u if there's an outgoing edge from v to u). If the player moves his/her marble from vertex v to vertex u, the "character" of that round is the character written on the edge from v to u. There's one additional rule; the ASCII code of character of round i should be greater than or equal to the ASCII code of character of round i - 1 (for i > 1). The rounds are numbered for both players together, i. e. Max goes in odd numbers, Lucas goes in even numbers. The player that can't make a move loses the game. The marbles may be at the same vertex at the same time.

Since the game could take a while and Lucas and Max have to focus on finding Dart, they don't have time to play. So they asked you, if they both play optimally, who wins the game?

You have to determine the winner of the game for all initial positions of the marbles.

Input

The first line of input contains two integers n and m (2 ≤ n ≤ 100, ).

The next m lines contain the edges. Each line contains two integers vu and a lowercase English letter c, meaning there's an edge from vto u written c on it (1 ≤ v, u ≤ nv ≠ u). There's at most one edge between any pair of vertices. It is guaranteed that the graph is acyclic.

Output

Print n lines, a string of length n in each one. The j-th character in i-th line should be 'A' if Max will win the game in case her marble is initially at vertex i and Lucas's marble is initially at vertex j, and 'B' otherwise.

Examples
input
4 4 1 2 b 1 3 a 2 4 c 3 4 b
output
BAAA ABAA BBBA BBBB
input
5 8 5 3 h 1 2 c 3 1 c 3 2 r 5 1 r 4 3 z 5 4 r 5 2 h
output
BABBB BBBBB AABBB AAABA AAAAB
Note

Here's the graph in the first sample test case:

Here's the graph in the second sample test case:

 

题意:两个人在DAG上玩游戏,每个人可以沿着边上走,每条边上有一个字母,每个人只能走的边上的字母必须大于等于上一个人走的边的字母

求两个人起点所有情况的胜负情况。

思路:

设(bool) dp u v k 表示一个人在u 另一个人在v 上一条边是k的胜负值,则若u走到i节点,而dp v i edge(u->i)为0 则dp u v k为1,然后在图上转移。

 代码:

1 //#include "bits/stdc++.h" 2 #include "cstdio" 3 #include "map" 4 #include "set" 5 #include "cmath" 6 #include "queue" 7 #include "vector" 8 #include "string" 9 #include "cstring"10 #include "time.h"11 #include "iostream"12 #include "stdlib.h"13 #include "algorithm"14 #define db double15 #define ll long long16 //#define vec vector
17 #define Mt vector
18 #define ci(x) scanf("%d",&x)19 #define cd(x) scanf("%lf",&x)20 #define cl(x) scanf("%lld",&x)21 #define pi(x) printf("%d\n",x)22 #define pd(x) printf("%f\n",x)23 #define pl(x) printf("%lld\n",x)24 #define rep(i, x, y) for(int i=x;i<=y;i++)25 const int N = 1e6 + 5;26 const int mod = 1e9 + 7;27 const int MOD = mod - 1;28 const db eps = 1e-10;29 const db PI = acos(-1.0);30 using namespace std;31 int ans[105][105][30];32 int mp[105][105],n,m;33 bool dfs(int u,int v,int x)34 {35 if(ans[u][v][x]) return ans[u][v][x];36 for(int i=1;i<=n;i++){37 if(x>mp[u][i]) continue;38 if(!dfs(v,i,mp[u][i])) return ans[u][v][x]=1;//(v,i,mp[u][i]) lost =>(u,v,x) win!39 }40 return ans[u][v][x]=0;//it can't win anyway41 }42 int main()43 {44 ci(n),ci(m);45 memset(mp,-1, sizeof(mp));46 for(int i=0;i

 

 

转载于:https://www.cnblogs.com/mj-liylho/p/8387838.html

你可能感兴趣的文章
如何激活windows的远程终端
查看>>
清晰还原!Photoshop处理人物模糊照片
查看>>
三角传输的在链路均衡项目中的灵活应用
查看>>
SOA面向服务架构简述
查看>>
技术分享连载(七十九)
查看>>
RPM命令和APT
查看>>
非对称网络不通 子网掩码是“祸首”
查看>>
gtest框架的介绍与应用
查看>>
Windows下打印服务器的管理(二)
查看>>
UWA TIPS:让你的项目更懂你!
查看>>
smarty手记2
查看>>
Windows server 2012 新功能试用---- powershell 3.0 进程和服务的操作
查看>>
c#开源消息队列中间件EQueue 教程
查看>>
Routeros2.9.7安装总结
查看>>
关于人工智能的实现(猜测)
查看>>
什么是DBA[WHAT'S MEANING OF DBA]
查看>>
Hyper-V Server 虚拟光纤通道
查看>>
IDEA控制台输出中文乱码的问题及解决方案
查看>>
VDI序曲三十 APP-V4.6SP1之OFFICE07补丁升级
查看>>
我的“技术架构”之旅
查看>>