Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int n,m;
- cin>>n;
- cin>>m;
- int temp;
- int * k=new int[m];
- for (int i=0;i<m;i++)
- cin>>k[i];
- int* DP=new int[n+1]; //массив состояний, показывающий победил ли 1 игрок при заданном кол-ве камней
- for (int i=0;i<n+1;i++)
- DP[i]=-1;
- DP[1]=0;
- // for(int i=1;i<=n;i++)
- // {
- // cout<<DP[i]<<" ";
- // }
- // cout<<endl;
- for (int j=1;j<=n;j++)
- {
- if (DP[j]==1 ) continue;
- for (int i=0;i<m;i++)
- {
- temp=j-k[i];
- if (temp>0)
- if (DP[temp]==0){ if (DP[j]==-1)DP[j]=1;
- }
- }
- if (DP[j]==-1) DP[j]=0;
- }
- // for(int i=1;i<=n;i++)
- // {
- // cout<<DP[i]<<" ";
- // }
- if (DP[n]==1) cout<<1;
- else cout<<2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement