前言
思路
完全是混合背包裸题了
无非就是判断是否使用 多重背包(二进制优化 和 完全背包罢了
CODE
int cal(string a,string b)
{
int x=0,y = 0 ;
int temp = 0 ;
for(int i = 0 ;i< a.size();i++)
{
if(a[i] == ':')
{
temp/=10;
x+=temp*60;
temp = 0 ;
continue;
}
temp += a[i]-'0';
temp *=10;
}
x+=temp/10;
temp = 0 ;
for(int i = 0 ;i< b.size();i++)
{
if(b[i] == ':')
{
temp/=10;
y+=temp*60;
temp = 0 ;
continue;
}
temp += b[i]-'0';
temp *=10;
}
y+=temp/10;
return y-x;
}
void solve()
{
string s1,s2;cin>>s1>>s2;
cin>>n;m=cal(s1,s2);
// cout<<m<<endl;
for(int i=1;i<=n;i++)
{
int v,w,s;
cin>>v>>w>>s;
if(!s)
{
for(int j = v;j<=m;j++)
f[j] = max(f[j],f[j-v]+w);
}else
{
for(int k=1;k<=s;k*=2)
{
for(int j = m;j>=k*v;j--)
f[j] = max(f[j],f[j-k*v]+k*w);
s-=k;
}
if(s)
{
for(int j = m;j>=s*v;j--)
f[j] = max(f[j],f[j-s*v]+s*w);
}
}
}
cout<<f[m]<<endl;
}