解题思路:
构建字母树,通过dfs判断每一局的输赢,再根据K进行分类讨论。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define LL long long
using 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;
}