daily pastebin goal
48%
SHARE
TWEET

Untitled

a guest Feb 23rd, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///Solutie - Moca Andrei - 100p
  2. #include <iostream>
  3. using namespace std;
  4. const int Inf = 0x3f3f3f3f;
  5. int n, k, G, g[1002], nr[100002];
  6. void Halloween();
  7. int main()
  8. {
  9.     cin >> n >> G;
  10.     for (int i = 1; i <= G; i++)
  11.         nr[i] = Inf;
  12.     for (int i = 1; i <= n; ++i)
  13.         cin >> g[i];
  14.     Halloween();
  15.     if (nr[G] < Inf)
  16.         cout << nr[G];
  17.     else
  18.         cout << "NU";
  19. }
  20. void Halloween()
  21. {
  22.     nr[0] = 0;
  23.     for (int i = 1; i <= n; ++i)
  24.         for (int j = G - g[i]; j >= 0; --j)
  25.             if (nr[j] != Inf && nr[j + g[i]] > nr[j] + 1)
  26.                 nr[j + g[i]] = nr[j] + 1;
  27. }
RAW Paste Data
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