G2A Many GEOs
SHARE
TWEET

Untitled

a guest Apr 5th, 2020 125 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     bool compute(vector<int> &used,int desiredTotal,bool turn,int maxChoosableInteger,vector<int> &hod){
  4.         if (desiredTotal <= 0){
  5.             if (turn == 0){
  6.                 for(int i = 0; i < hod.size(); i++){
  7.                     cout << hod[i] << " ";
  8.                 }
  9.                 cout << endl;
  10.             }
  11.            
  12.             return turn == 1;
  13.         }
  14.         bool ans = false;
  15.         for(int i = 1; i <= maxChoosableInteger; i++){
  16.             if (desiredTotal - i >= 0 && !used[i]){
  17.                 used[i] = true;
  18.                 hod.push_back(i);
  19.                 ans |= compute(used,desiredTotal - i,!turn,maxChoosableInteger,hod);
  20.                 used[i] = false;
  21.                 hod.pop_back();
  22.             }
  23.         }
  24.         return ans;
  25.     }
  26.     bool canIWin(int maxChoosableInteger, int desiredTotal) {
  27.         vector<int> used(maxChoosableInteger + 1);
  28.         vector<int> hod;
  29.         return compute(used,desiredTotal,0,maxChoosableInteger,hod);
  30.     }
  31. };
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top