Advertisement
askarulytarlan

E regional

Dec 7th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int c, n, a[30], ans;
  6.  
  7.  
  8. void rec(int v, int cur){
  9. if(cur > c){
  10. return;
  11. }
  12. if(cur == c){
  13. ans = 1000;
  14. return;
  15. }
  16. for(int i = v; i <= n; i++){
  17. if(ans == 1000){
  18. return;
  19. }
  20. rec(i, cur + a[i]);
  21. }
  22. }
  23.  
  24. int main(){
  25. //freopen("E.in", "r", stdin);
  26. //freopen("E.out", "w", stdout);
  27. scanf("%d %d", &c, &n);
  28. for(int i = 1; i <= n; i++){
  29. cin >> a[i];
  30. }
  31. for(int i = 1; i <= n; i++){
  32. rec(i, a[i]);
  33. if(ans == 1000){
  34. printf("YES");
  35. return 0;
  36. }
  37.  
  38. }
  39. printf("NO");
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement