Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement