Advertisement
SergeyPGUTI

10.1.4(Время забирать камни)

May 27th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. using namespace std;
  5.  
  6.  
  7. int main()
  8. {
  9.  
  10.     int n,m;
  11.     cin>>n;
  12.     cin>>m;
  13.     int temp;
  14.     int * k=new int[m];
  15.     for (int i=0;i<m;i++)
  16.         cin>>k[i];
  17.     int* DP=new int[n+1]; //массив состояний, показывающий победил ли 1 игрок при заданном кол-ве камней
  18.     for (int i=0;i<n+1;i++)
  19.         DP[i]=-1;
  20.         DP[1]=0;
  21.  
  22.  
  23. //    for(int i=1;i<=n;i++)
  24. //    {
  25. //        cout<<DP[i]<<" ";
  26. //    }
  27. //    cout<<endl;
  28.  
  29.     for (int j=1;j<=n;j++)
  30.     {
  31.         if (DP[j]==1 ) continue;
  32.         for (int i=0;i<m;i++)
  33.         {
  34.             temp=j-k[i];
  35.             if (temp>0)
  36.                 if (DP[temp]==0){ if (DP[j]==-1)DP[j]=1;
  37.                 }
  38.         }
  39.         if (DP[j]==-1) DP[j]=0;
  40.     }
  41.  
  42. //    for(int i=1;i<=n;i++)
  43. //    {
  44. //        cout<<DP[i]<<" ";
  45. //    }
  46.     if (DP[n]==1) cout<<1;
  47.         else cout<<2;
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement