chillurbrain

4. Время забирать камни

May 22nd, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. int main(){
  7.     int n,m;
  8.     scanf("%d %d",&n,&m);
  9.    
  10.     int a[50];
  11.     for(int i = 0;i<m;++i) scanf("%d",&a[i]);
  12.    
  13.     bool win[10001];
  14.     win[0] = true;
  15.    
  16.     for(int i = 1;i<=n;++i){
  17.         win[i] = false;
  18.        
  19.         for(int j = 0;j<m;++j)
  20.             if(i>=a[j] && !win[i-a[j]])
  21.                 win[i] = true;
  22.     }
  23.    
  24.     if(win[n]) putchar('1');
  25.     else putchar('2');
  26.    
  27.     return 0;
  28. }
Add Comment
Please, Sign In to add comment