【字典树+dp】 codeforces 455B A Lot of Games
2014-08-09 18:49
459 查看
00 代表不能控制 01代表败,10代表胜,11代表能输能赢。。
#include <iostream> #include <queue> #include <stack> #include <map> #include <set> #include <bitset> #include <cstdio> #include <algorithm> #include <cstring> #include <climits> #include <cstdlib> #include <cmath> #include <time.h> #define maxn 100005 #define maxm 100005 #define eps 1e-10 #define mod 3 #define INF 1e17 #define lowbit(x) (x&(-x)) #define ls o<<1 #define rs o<<1 | 1 #define lson o<<1, L, mid #define rson o<<1 | 1, mid+1, R typedef long long LL; //typedef int LL; using namespace std; int next[maxn][26]; int vis[maxn]; int top, root; char s[maxn]; void insert(void) { int len = strlen(s); int now = root, tmp; for(int i = 0; i < len; i++) { tmp = s[i] - 'a'; if(!next[now][tmp]) next[now][tmp] = ++top; now = next[now][tmp]; } } int dfs(int now) { int ok = 0, ans = 0; for(int i = 0; i < 26; i++) if(next[now][i]) { ok = 1; ans |= dfs(next[now][i])^3; } if(!ok) ans = 1; return ans; } int main(void) { int n, k; top = root = 1; scanf("%d%d", &n, &k); for(int i = 1; i <= n; i++) { scanf("%s", s); insert(); } int tmp = dfs(root); if(tmp == 3) printf("First\n"); else if(k&1 && tmp == 2) printf("First\n"); else printf("Second\n"); return 0; }
相关文章推荐
- CodeForces 455B A Lot of Games 字典树 博弈
- codeforces 455B A Lot of Games(博弈,字典树)
- Codeforces 455B A Lot of Games(字典树+博弈)
- codeforces 455B A Lot of Games(博弈,字典树)
- 字典树+博弈 CF 455B A Lot of Games(接龙游戏)
- Codeforces 455B A Lot of Games 字典树上博弈
- CodeForces 456D Elections(字典树+dp)
- CodeForces 456D Elections(字典树+dp)
- CF456D A Lot of Games (字典树+DP)
- Codeforces 455B A Lot of Games 字典树上博弈
- CodeForces-731E Funny Game(DP+Games)
- Codeforces 455B A Lot of Games
- Codeforces 557E - Ann and Half-Palindrome (字典树+DP)
- 【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
- codeforces727F Polycarp's problems(dp)
- [DP] Codeforces 403D #236 (Div. 1) D. Beautiful Pairs of Numbers