Advertisement
sherry_ahmos

Untitled

Mar 18th, 2022
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <cstdlib>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <iomanip>
  7.  
  8. using namespace std;
  9. #define ll long long
  10. void sherry()
  11. {
  12.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  13. #ifndef ONLINE_JUDGE
  14.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  15. #endif
  16. }
  17.  
  18. int a;
  19. ll b;
  20. int arr[20];
  21. int ind = 0;
  22. ll sum = 0;
  23. bool recursion(ll sum, int ind)
  24. {
  25.     if (ind == a)
  26.     {
  27.         return sum == b;
  28.     }
  29.     return recursion(sum + arr[ind], ind + 1) || recursion(sum - arr[ind], ind + 1);
  30. }
  31. int main()
  32. {
  33.     sherry();
  34.     cin >> a >> b;
  35.     for (int i = 0; i < a; i++)
  36.         cin >> arr[i];
  37.  
  38.     recursion(0, 0) ? cout << "YES" : cout << "NO";
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement