您的位置:首页 > 其它

【字典树+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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: