Mohd__Messi

New Sol for The Chocolate boy

Apr 7th, 2021
72
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. #define vi vector<int>
  3. #define ll long long
  4. using namespace std;
  5. ll dp[1002][1002][2];
  6. vector<ll> v1,v2;
  7. ll knapsack(int n,int m,int flag)
  8. {
  9.   if(m<0)
  10.    return INT_MIN;
  11.   if(n==0)
  12.    return 0;
  13.   if(dp[n][m][flag]!=-1)
  14.    return dp[n][m][flag];
  15.    
  16.   if(flag==0)
  17.     return dp[n][m][flag]=max(v2[n-1]+knapsack(n-1,m-v1[n-1],0),max(v2[n-1]+knapsack(n-1,m-v1[n-1]/2,1),knapsack(n-1,m,0)));
  18.   else
  19.     return dp[n][m][flag]=max(v2[n-1]+knapsack(n-1,m-v1[n-1],1),knapsack(n-1,m,1));  
  20.  
  21. }
  22. int main()
  23. {
  24.     ios_base::sync_with_stdio(false);cin.tie(NULL);
  25.     int n,m;
  26.     cin>>n>>m;
  27.     string s[n];
  28.     char d[n];int a[n],b[n];
  29.     for(int i=0;i<n;i++)
  30.      cin>>s[i]>>d[i]>>a[i]>>b[i];
  31.     memset(dp,-1,sizeof(dp));
  32.     for(int i=0;i<n;i++)
  33.     {
  34.       if(d[i]=='S')
  35.       {
  36.         v1.push_back(a[i]);
  37.         v2.push_back(b[i]);
  38.         }      
  39.     }
  40.     int n1=v1.size();
  41.     cout<<knapsack(n1,m,0);
  42.     return 0;
  43. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×