Advertisement
srijan44

CellMitosis(DP)

Feb 16th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long int
  4.  
  5. ll CellMitosis(int n,int x,int y,int z){
  6.     ll *dp = new ll[n+1];
  7.     dp[0]=0;
  8.     dp[1]=0;
  9.  
  10.     for(int i=2;i<=n;i++){
  11.         if(i&1){
  12.             dp[i] = min((dp[i-1]+y),dp[(i+1)/2]+x+z);
  13.         }
  14.         else{
  15.             dp[i] = min((dp[i/2]+x),(dp[i-1]+y));
  16.         }
  17.     }
  18.  
  19.     return dp[n];
  20. }
  21. int main() {
  22.  
  23.     #ifndef ONLINE_JUDGE
  24.     // for getting input from input.txt
  25.     freopen("input.txt", "r", stdin);
  26.     // for writing output to output.txt
  27.     freopen("output.txt", "w", stdout);
  28.     #endif
  29.  
  30.      ll n; cin >> n;
  31.      ll x,y,z;
  32.  
  33.      cin >> x >> y >> z;
  34.  
  35.    
  36.      cout << CellMitosis(n,x,y,z) << endl;
  37.  
  38.  
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement