Advertisement
Josif_tepe

Untitled

Oct 20th, 2021
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int n;
  5. int y;
  6. int niza[100];
  7. int dp[10000000];
  8. const int MOD = 1e9 + 7;
  9. int c(int y1){
  10.     if(y1==0){
  11.         return 1;
  12.     }
  13.  
  14. if(dp[y1]!=-1){
  15.     return dp[y1];
  16. }
  17. int result=0;
  18. for(int i=0; i<n; i++){
  19.     if(y1-niza[i]>=0){
  20.         result+=c(y1-niza[i]);
  21.         result %= MOD;
  22.     }
  23. }
  24. return dp[y1]=result;
  25. }
  26.  
  27.  
  28. int main()
  29. {
  30.  
  31. cin>>n;
  32. cin>>y;
  33. for(int i=0; i<=y; i++){
  34.     dp[i]=-1;
  35. }
  36. for(int i=0; i<n; i++){
  37.     cin>>niza[i];
  38. }
  39. cout<<c(y);
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement