【题解】Music Festival(树状数组优化dp)

Gym - 101908F

题意:有\(n\)种节目,每种节目有起始时间和结束时间和权值。同一时刻只能看一个节目(边界不算),在所有种类都看过至少一遍的情况下最大收益

设\(dp(s,i)\)表示已经看过\(s\)集合中的节目,且看过的节目的结束时间是\(i\)的最大收益。

转移:

\[dp(s,e[t].r)=\max(dp(s,k),dp(s-e[t].id,k))+e[t].val,k\le e[t].l
\]

由于\(O(m^3)\)不能过1000,但可以看到转移是一段前缀,所以直接树状数组优化就好。

注意转移的顺序,可以发现\(r\)可以作为转移状态。可能会有r相同的情况,但不影响答案。

复杂度\(O(m^2\log m)\)

//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm> using namespace std; typedef long long ll;
inline int qr(){
register int ret=0,f=0;
register char c=getchar();
while(!isdigit(c))f|=c==45,c=getchar();
while(isdigit(c)) ret=ret*10+c-48,c=getchar();
return f?-ret:ret;
}
const int maxn=86405;
const int inf=0x3f3f3f3f;
int dp[1<<10|1][maxn]; struct E{
int l,r,id,val;
inline bool operator <(const E&a)const{return r<a.r;}
}e[1001];
int n,cnt,len;
inline int que(const int&pos,const int*a){
int ret=-inf;
for(int t=pos;t>0;t-=t&-t) ret=max(ret,a[t]);
return ret;
} inline void upd(const int&pos,const int&tag,int*a){
for(int t=pos;t<=len;t+=t&-t) a[t]=max(a[t],tag);
} int main(){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
//freopen("out.out","w",stdout);
#endif
n=qr();
memset(dp,0xcc,sizeof dp);
for(int t=1;t<=n;++t){
int m=qr();
for(int i=1,t1,t2,t3;i<=m;++i) t1=qr(),t2=qr(),t3=qr(),e[++cnt]={t1,t2,t,t3};
}
sort(e+1,e+cnt+1);
len=e[cnt].r+1;
memset(dp[0],0,sizeof dp[0]);
for(int t=1;t<=cnt;++t){
for(int s=0;s<1<<n;++s){
if(s&(1<<e[t].id>>1)){
int g=s^(1<<e[t].id>>1);
int f=max(que(e[t].l,dp[s]),que(e[t].l,dp[g]))+e[t].val;
upd(e[t].r,f,dp[s]);
}
}
}
int g=que(len,dp[(1<<n)-1]);
cout<<max(g,-1)<<endl;
return 0;
}

最新文章

  1. java 开发中经常问到得懒汉模式 (单利模式)
  2. Windows 10系统更换Windows 7系统磁盘分区注意事项二
  3. CSS 属性 - position讲解
  4. arch框架人员、组织说明
  5. mysql 内连接 左连接 右连接 外连接
  6. 14.Apache配置
  7. iOS开发UI篇—UITabBarController生命周期(使用storyoard搭建)
  8. VBA开发经验总结之二:灵活运用工作表属性
  9. Yii 2.0: yii2-highcharts-widget创建饼状图
  10. 关于.netFramework概述
  11. 关于在git添加远程地址的过程中遇到的问题
  12. nginx错误界面优化和日志管理
  13. mybatis 中 foreach collection的三种用法(转)
  14. 详解 JVM Garbage First(G1) 垃圾收集器(转载)
  15. CodeForces - 327D Block Tower
  16. HDU 5792 World is Exploding(树状数组+离散化)
  17. spring boot 中使用servlet
  18. SLAM产品化的一些思考
  19. opencv-python 学习初探2 去图片水印
  20. Goroutines和Channels(五)

热门文章

  1. es6 set简析
  2. 在phpstudy中nginx伪静态配置
  3. PHP会话技术
  4. ubuntu netstat 查看端口占用情况
  5. 洛谷P4018 Roy&amp;October之取石子 题解 博弈论
  6. 2019-1-29-win10-uwp-使用-Microsoft.Graph-发送邮件
  7. iptables command 常用命令列表
  8. HDU 2717 宽搜第一题、
  9. 利用SpEL 表达式实现简单的动态分表查询
  10. python模块之模块导入