Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <cstdio>
- #include <vector>
- #define pb push_back
- using namespace std;
- int vis[112345];
- int main()
- {
- ios::sync_with_stdio(0);
- int valor, n, x, TC = -1, tam, curr;
- bool check;
- vector<int> comb;
- while((cin >> valor >> n) && n)
- {
- check = 0;
- comb.clear();
- TC++;
- while(n--)
- {
- cin >> x;
- if(x == valor)
- check = 1;
- tam = comb.size();
- for(int i = 0; i < tam; i++)
- {
- curr = comb[i] + x;
- if(curr <= valor && vis[curr] <= TC)
- {
- comb.pb(curr);
- vis[curr] += TC + 1;
- if(curr == valor)
- check = 1;
- }
- }
- comb.pb(x);
- }
- if(check)
- cout << "sim";
- else
- cout << "nao";
- cout << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement