fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int n, t, dp[1000005], c[1005];
  6.  
  7. const int mod = 1e9 + 7;
  8.  
  9. int main() {
  10. cin >> t >> n;
  11. for (int i = 1; i <= t; i++)
  12. cin >> c[i];
  13. /// if (n == 0) return 1
  14. /// TH co so
  15. /// 1, 2, 3, 4, 5, 6
  16.  
  17. /// c[1], c[2], ...., c[t]
  18.  
  19. dp[0] = 0;
  20.  
  21. for (int i = 1; i <= n; i++) {
  22. dp[i] = 10000000;
  23.  
  24. for (int j = 1; j <= t; j++)
  25. if (i - c[j] >= 0) {
  26. /// tren tay 230k
  27. /// c[j] = 50k
  28. /// tay cua a co 1 to tien va con lai (230 - 50)k
  29. dp[i] = min(dp[i], dp[i - c[j]] + 1);
  30. }
  31. }
  32. if (dp[n] == 10000000) cout << -1;
  33. else
  34. cout << dp[n];
  35.  
  36. }
  37.  
  38.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty