Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <cstdio>
  4. #include <vector>
  5. #define pb push_back
  6. using namespace std;
  7.  
  8. int vis[112345];
  9.  
  10.  
  11. int main()
  12. {
  13.     ios::sync_with_stdio(0);
  14.  
  15.     int valor, n, x, TC = -1, tam, curr;
  16.     bool check;
  17.     vector<int> comb;
  18.  
  19.     while((cin >> valor >> n) && n)
  20.     {
  21.         check = 0;
  22.         comb.clear();
  23.         TC++;
  24.  
  25.         while(n--)
  26.         {
  27.  
  28.             cin >> x;
  29.             if(x == valor)
  30.                 check = 1;
  31.  
  32.             tam = comb.size();
  33.  
  34.             for(int i = 0; i < tam; i++)
  35.             {
  36.                 curr = comb[i] + x;
  37.                 if(curr <= valor && vis[curr] <= TC)
  38.                 {
  39.                     comb.pb(curr);
  40.                     vis[curr] += TC + 1;
  41.                     if(curr == valor)
  42.                         check = 1;
  43.                 }
  44.             }
  45.  
  46.             comb.pb(x);
  47.  
  48.         }
  49.         if(check)
  50.             cout << "sim";
  51.         else
  52.             cout << "nao";
  53.         cout << '\n';
  54.  
  55.  
  56.     }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement