fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. const ll MOD = 1e9 + 7;
  5.  
  6. ll dp[1000005]; // dp[i] = số cách tạo tổng i
  7. ll a[105];
  8. int n, k;
  9.  
  10. int main() {
  11. cin >> n >> k;
  12. for (int i = 1; i <= n; i++) cin >> a[i];
  13. sort(a + 1, a + n + 1); // đảm bảo thứ tự tăng dần
  14.  
  15. dp[0] = 1; // Có 1 cách để tạo tổng 0 (không chọn gì)
  16.  
  17. for (int i = 1; i <= n; i++) { // duyệt từng loại đồng xu theo thứ tự tăng dần
  18. for (int j = a[i]; j <= k; j++) { // từ a[i] đến k
  19. dp[j] = (dp[j] + dp[j - a[i]]) % MOD;
  20. }
  21. }
  22.  
  23. cout << dp[k];
  24. }
  25.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
1