-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathK-Stones.cpp
52 lines (42 loc) · 888 Bytes
/
K-Stones.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define MAX 100001
#define MOD 1000000007
using namespace std;
bool play(int n,int k, int a[])
{
bool dp[n][k+1];
memset(dp,0,sizeof(dp));
for(int i=1;i<=k;++i)
{
bool flag = 0;
for(int j=0 ;j<n;++j)
{
if(a[j] > i)
continue;
dp[j][i] = dp[j][i-a[j]]^1;
flag += dp[j][i];
if(flag)
break;
}
if(flag)
for(int j=0;j<n;++j)
dp[j][i] = 1;
}
return dp[0][k];
}
int32_t main()
{
int n,k;
cin>>n>>k;
int a[n];
for(int i=0;i<n;++i)
cin>>a[i];
int player = play(n,k,a);
if(player)
cout<<"First"<<endl;
else
cout<<"Second"<<endl;
return 0;
}