Advertisement
tepyotin2

Strange Auction

May 8th, 2025
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int w, p;
  6. int a, b;
  7. int dp[1000001];
  8.  
  9. long dfs(int cur){
  10.     if(cur<p) return 0;
  11.     //cout << cur << '\n';
  12.     if(cur==p){
  13.         //cout << "---" << '\n';
  14.         return 1;
  15.     }
  16.     if(dp[cur]>0){
  17.         //cout << "HI" << ", dp[cur]: " << dp[cur] << '\n';
  18.         //cout << "===" << '\n';
  19.         return dp[cur];
  20.     }
  21.     dp[cur] = dfs(cur-a)+dfs(cur-b);
  22.     return dp[cur];
  23. }
  24.  
  25. int main(){
  26.     //freopen("auction.in", "r", stdin);
  27.    
  28.     cin >> w >> p;
  29.     cin >> a >> b;
  30.     dfs(w);
  31.     cout << dp[w] << '\n';
  32.    
  33.     return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement