-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThe_chocolate_boy.cpp
More file actions
71 lines (65 loc) · 1.52 KB
/
The_chocolate_boy.cpp
File metadata and controls
71 lines (65 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<bits/stdc++.h>
using namespace std;
int dp[1001][1001][2];
void fun()
{
for(int i=0;i<1001;i++)
{
for(int j=0;j<1001;j++)
{
dp[i][j][0]=dp[i][j][1]=-1;
}
}
}
int func1(int n,int m,vector<pair<char,pair<int,int>>>vec,int p=0)
{
for(int i=0;i<=n;i++)
{for(int j=0;j<=m;j++)
{for(p=0;p<2;p++)
{if(i==0||j==0)
{dp[i][j][p]= 0;
// dp[i][j][1]=0;
}
else if(p==1)
{
if(vec[i-1].second.first>j)
dp[i][j][p]=dp[i-1][j][p];
else
dp[i][j][p]=max(vec[i-1].second.second+dp[i-1][j-vec[i-1].second.first][p],dp[i-1][j][p]);
}
else
{if(vec[i-1].second.first>j)
{
if(((vec[i-1].second.first)/2)<=j)
dp[i][j][p]=max(vec[i-1].second.second+dp[i-1][j-((vec[i-1].second.first)/2)][1],dp[i-1][j][p]);
else
dp[i][j][p]=dp[i-1][j][p];}
else
dp[i][j][p]=max(vec[i-1].second.second+dp[i-1][j-((vec[i-1].second.first)/2)][1],max(vec[i-1].second.second+dp[i-1][j-vec[i-1].second.first][p],dp[i-1][j][p]));}
}
}
}
return max(dp[n][m][0],dp[n][m][1]);}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input1.txt", "r", stdin);
freopen("output1.txt", "w", stdout);
#endif
fun();
int n,m;
cin>>n>>m;
vector<pair<char,pair<int,int>>>vec;
for( int i=0;i<n;i++)
{
string s;
char ch;
int p,q;
cin>>s>>ch>>p>>q;
if(ch=='S')
vec.push_back({ch,{p,q}});
}
int ans=func1(vec.size(),m,vec,0);
cout<<ans;
}