Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int s[1001];
  5.  
  6. int oshit[10001];
  7.  
  8. int main()
  9. {
  10.     int x;
  11.     int inf = 4202137;
  12.  
  13.     cin >> x;
  14.  
  15.     for(int i = 0; i < x; i++)
  16.     {
  17.         cin >> s[i];
  18.     }
  19.  
  20.     for(int i = 1; i <= 10000; i++)
  21.     {
  22.         oshit[i] = inf;
  23.     }
  24.  
  25.     for(int i = 0; i < x ; i++)
  26.     {
  27.  
  28.         for(int l = s[i]; l <= 10000; l++)
  29.         {
  30.             if(oshit[l - s[i]] != inf)
  31.             {
  32.                 oshit[l] = oshit[l - s[i]] + 1;
  33.             }
  34.         }
  35.  
  36.     }
  37.     int kwota;
  38.     cin >> kwota;
  39.     if(oshit[kwota] != inf)
  40.     {
  41.             cout << oshit[kwota];
  42.     }
  43.     else if(oshit[kwota] == inf)
  44.     {
  45.             cout << "NIE";
  46.     }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement