Codeforces #260(Div 2) D A lot of games(字母树+树形dp)
来源:互联网 发布:淘宝hd平板官网下载 编辑:程序博客网 时间:2024/06/05 19:53
解题思路:
构建字母树,通过dfs判断每一局的输赢,再根据K进行分类讨论。
#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <algorithm>#define LL long longusing namespace std;const int maxn = 100000 + 10;string s;int G[maxn][30];int win[maxn] , lose[maxn];int n , k, cur;void insert(string str){int len = str.length();int root = 0;for(int i=0;i<len;i++){int x = s[i] - 'a';if(!G[root][x]) G[root][x] = ++cur;root = G[root][x];}}void dfs(int u){int ok = 0;for(int i=0;i<=26;i++){if(G[u][i]){dfs(G[u][i]);ok = 1;win[u] |= !win[G[u][i]];lose[u] |= !lose[G[u][i]];}}if(!ok) lose[u] = 1;}int main(){while(scanf("%d%d",&n,&k)!=EOF){cur = 0;for(int i=1;i<=n;i++){cin>>s;insert(s);}dfs(0);if(k == 1) win[0] ? printf("First\n") : printf("Second\n");else if(win[0] && lose[0]){printf("First\n");}else if(win[0]){(k & 1) ? printf("First\n") : printf("Second\n");}else printf("Second\n");}return 0;}
0 0
- Codeforces #260(Div 2) D A lot of games(字母树+树形dp)
- Codeforces Round #260 (Div. 2) D. A Lot of Games
- A Lot of Games - CodeForces #260 (Div. 2) D Trie树
- codeforces content#260 D A Lot of Games
- 【字典树+dp】 codeforces 455B A Lot of Games
- Codeforces 456 Problem D A Lot of Games
- Codeforces #260 (Div. 1) B. A Lot of Games(数据结构:trie+DFS)
- Codeforces Round #260 (Div. 1) B. A Lot of Games Trie + 博弈
- Codeforces Round #260(Div2) Problem D. A Lot of Games
- (CF) D. A Lot of Games
- Codeforces 455B A Lot of Games(字典树+博弈)
- 【CodeForces】445B A Lot of Games 字典树博弈
- CodeForces 455B A Lot of Games 字典树 博弈
- codeforces 455B. A Lot of Games
- codeforces 455B A Lot of Games
- codeforces 455B A Lot of Games
- CodeForces 455B A Lot of Games
- codeforces 455B A Lot of Games
- PythonOpenCV--Rtrees随机森林
- HDU4919 Exclusive or(Java大数推公式)
- android.graphics.drawable.Drawable
- CRM Badi
- 二叉树的创建及中序遍历
- Codeforces #260(Div 2) D A lot of games(字母树+树形dp)
- php $_SERVER中的SERVER_NAME 和HTTP_HOST的区别
- Visitor 访问者模式
- 黑马程序员—TreeMap练习-字母出现的次数
- POJ 3356 AGTC.
- TextView功能总结(1)
- LeetCode刷题笔录3Sum
- Python 正则表达式查找字符串中特定字符
- AAA服务器的配置