题目

有 \(n\) 棵樱花,有三种:

  1. 只能看一次
  2. 最多看 \(A_i\) 遍
  3. 能无限看

看每棵樱花都需要一定时间 \(T_i\),求从 \(T_s\) 开始,到 \(T_e\) 结束(时间)最多能看多少樱花。

题解

混合背包板子,01 背包相当于 \(1\) 个物品的多重背包,完全背包相当于 inf 个物品的多重背包,都用多重背包即可。

要二进制拆分优化,注意多重背包的 inf 不能开太大,不然会 RE .

#include<iostream>
#include<ctime>
#include<queue>
#include<stack>
#include<cmath>
#include<iterator>
#include<cctype>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
namespace Main
{
const int N=1000005,INF=0x3f3f3f3f;
int t,T,n,c[N],v[N],dp[N];
struct node{int T,C,P;}a[N];
void split() // 二进制拆分
{
for (int i=0;i<n;i++)
{
int z=1;
while (a[i].P) // index from 0 => index from 1
{
c[++T]=z*a[i].T; v[T]=z*a[i].C; a[i].P-=z; z<<=1;
if (a[i].P<z){c[++T]=a[i].T*a[i].P; v[T]=a[i].C*a[i].P; break;}
}
}
}
void zbag() // 01 背包
{
for (int i=1;i<=T;i++)
for (int j=t;j>=c[i];j--)
dp[j]=max(dp[j],dp[j-c[i]]+v[i]);
}
inline void mbag(){split(); zbag();} // 多重背包
int main()
{
int hh1,mm1,hh2,mm2,Ts,Te;
scanf("%d:%d %d:%d %d",&hh1,&mm1,&hh2,&mm2,&n);
Ts=hh1*60+mm1; Te=hh2*60+mm2; t=Te-Ts;
for (int i=0;i<n;i++)
{
scanf("%d%d%d",&a[i].T,&a[i].C,&a[i].P);
if (!a[i].P) a[i].P=INF;
} mbag(); printf("%d",dp[t]);
return 0;
}
}
int main(){return Main::main();}

最新文章

  1. SQL Server 2012 Managed Service Account
  2. go 聊天室简单版总结
  3. hadoop+hive使用中遇到的问题汇总
  4. 有趣的问题--12 coins problem
  5. [bzoj4552][Tjoi2016][Heoi2016]排序
  6. SerialChat与Arduino的配合使用
  7. singleton注意
  8. Software caused connection abort: socket write error
  9. iOS关于打包出错
  10. uva 10154
  11. offsetParent和parentNode区别
  12. Linux 安装ibus极点五笔输入法备忘录
  13. Oracle Sql优化之lead,lag分析函数
  14. NIO基础篇(一)
  15. 【python学习笔记】5.条件、循环和其他语句
  16. LeetCode(25)-symmetric tree
  17. 从壹开始前后端分离 39 || 想创建自己的dotnet模板么?看这里
  18. SQL学习(1)初学实验:SQL Server基本配置及基本操作
  19. linux中gcc和g++的区别
  20. 面试官问,说一个你在工作非常有价值的bug

热门文章

  1. Doker从0-1
  2. jmeter 基础使用
  3. 143. Reorder List - LeetCode
  4. SSH管理多密钥
  5. ABP框架之——数据访问基础架构
  6. 【Azure 存储服务】Java Azure Storage SDK V12使用Endpoint连接Blob Service遇见 The Azure Storage endpoint url is malformed
  7. dubbo是如何实现可扩展的?
  8. C++:制作火把
  9. 如何用 UDP 实现可靠传输?
  10. 常用排序算法(一)-java实现