传送门

题意:\(n\)个位置,每个位置有价值\(v_i\)和重量\(p_i\),要选出一些位置,如果要选位置\(i\),那么前面选的重量之和要为\(l_i\),后面选的重量之和要为\(r_i\),求一个方案使得价值和最大

这个限制很舒服,可以设\(f_i\)为从前面开始选,选第\(i\)个的最大价值,转移枚举前面的\(j\),如果能从\(j\)转移过来,根据条件,要求\(l_i=l_j+p_i\&\&r_i=r_j-p_i\),记个转移前缀就可以输出方案了

但是这样还不优,我们可以发现对于一个\(i\),只有\(l_j+p_j+r_j=l_i+p_i+r_i\)的\(j\)能够转移过来,于是可以把所有\(l_i+p_i+r_i\)相等的放在一组,每一组里,记\(f_k\)为前缀重量为\(k\)的最大价值,转移从前往后枚举\(i\),从\(f_{l_i}\)向\(f_{l_i+p_i}\)转移,这一组的答案应为\(f_{l_i+p_i+r_i}\)

代码贼丑,轻\(\mathfrak{D}\)qwq

#include<bits/stdc++.h>
#define il inline
#define re register
#define LL long long
#define ull unsigned long long
#define db double
#define eps (1e-7) using namespace std;
const int N=200000+10,M=3000000+10;
il LL rd()
{
LL x=0,w=1;char ch=0;
while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
return x*w;
}
int f[M],hd[M],nt[N];
int n,a[N][4],ma;
int st[N],an[N],tt=0,pre[N],g[M]; int main()
{
n=rd();
for(int i=1;i<=n;i++)
{
a[i][0]=rd(),a[i][1]=rd(),a[i][2]=rd(),a[i][3]=rd();
int pp=a[i][1]+a[i][2]+a[i][3];
ma=max(ma,pp);
nt[i]=hd[pp],hd[pp]=i;
}
memset(f,-63,sizeof(f));
f[0]=0;
int ii=-1,ans=0,inf=f[1];
for(int h=0;h<=ma;h++)
{
if(!hd[h]) continue;
int st[N],tt=0;
for(int i=hd[h];i;i=nt[i]) st[++tt]=i;
for(int i=tt;i>=1;i--) f[a[st[i]][1]+a[st[i]][2]]=max(f[a[st[i]][1]+a[st[i]][2]],f[a[st[i]][2]]+a[st[i]][0]);
if(ans<f[h]) ans=f[h],ii=h;
for(int i=tt;i>=1;i--) f[a[st[i]][1]+a[st[i]][2]]=inf;
}
//printf("%d\n",ans);
if(ii>=0)
{
for(int i=hd[ii];i;i=nt[i]) st[++tt]=i;
for(int i=tt;i>=1;i--)
if(f[a[st[i]][1]+a[st[i]][2]]<f[a[st[i]][2]]+a[st[i]][0])
f[a[st[i]][1]+a[st[i]][2]]=f[a[st[i]][2]]+a[st[i]][0],pre[st[i]]=g[a[st[i]][2]],g[a[st[i]][1]+a[st[i]][2]]=st[i];
tt=0;
int nw=g[ii];
while(nw)
{
an[++tt]=nw,nw=pre[nw];
}
printf("%d\n",tt);
for(int i=tt;i>=1;i--) printf("%d ",an[i]);
}
else puts("0");
return 0;
}

CF28D Don't fear, DravDe is kind的更多相关文章

  1. CF28D Don't fear, DravDe is kind 背包

    题目传送门:http://codeforces.com/problemset/problem/28/D 题意:给你$N$个物品,每个物品有其价格$P_i$,之前必须要买的物品价格和$L_i$,之后必须 ...

  2. 【神仙题】【CF28D】 Don't fear, DravDe is kind

    传送门 Description 一个有N辆卡车的车队从城市Z驶向城市3,来到了一条叫做"恐惧隧道"的隧道.在卡车司机中,有传言说怪物DravDe在那条隧道里搜寻司机.有些司机害怕先 ...

  3. CodeForces 28D Don&#39;t fear, DravDe is kind dp

    主题链接:点击打开链接 为了让球队后,删除是合法的.也就是说,对于每一个车辆, l+r+c 一样,按l+r+c分类. 然后dp一下. #include <cstdio> #include ...

  4. [Codeforces 28D] Do not fear,DravDe is kind

    Brief Intro: 对于四元组(v,c,l,r),求其子序列中v最大的和,并使其满足: 1.Ci+Li+Ri相同 2.L1=0,Rn=0 3.Li=Sigma(C1...Ci-1) Soluti ...

  5. codeforces 28D(dp)

    D. Don't fear, DravDe is kind time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  6. 英语演讲稿——Get Along with Fear

    Hi. My name is Zhang Meng. I’m an engineer at Keysight. Today I’m not going to introduce my birthpla ...

  7. TED #05# How we can face the future without fear, together

    Rabbi Lord Jonathan Sacks: How we can face the future without fear, together 1. what was it like bei ...

  8. Codeforces Gym100812 L. Knights without Fear and Reproach-扩展欧几里得(exgcd)

    补一篇以前的扩展欧几里得的题,发现以前写错了竟然也过了,可能数据水??? 这个题还是很有意思的,和队友吵了两天,一边吵一边发现问题??? L. Knights without Fear and Rep ...

  9. Fear No More歌词

      "Fear No More"   Every anxious thought that steals my breath It's a heavy weight upon my ...

随机推荐

  1. 选择 Delphi 2007 ( CodeGear Delphi 2007 for Win32 Version 11.0.2837.9583 ) 的理由

    选择 Delphi 2007 ( CodeGear Delphi 2007 for Win32 Version 11.0.2837.9583 ) 的理由 我不喜欢用InstallRite的全自动安装包 ...

  2. VMware虚拟机看不到共享目录

    1. 确认VMtools已经装好,开启共享文件夹,设置好共享目录 2.执行命令 sudo mount -t vmhgfs .host:/ /mnt/hgfs如果出现错误: Error: cannot ...

  3. BZOJ3832[Poi2014]Rally——权值线段树+拓扑排序

    题目描述 An annual bicycle rally will soon begin in Byteburg. The bikers of Byteburg are natural long di ...

  4. 学习Spring Boot:(二十六)使用 RabbitMQ 消息队列

    前言 前面学习了 RabbitMQ 基础,现在主要记录下学习 Spring Boot 整合 RabbitMQ ,调用它的 API ,以及中间使用的相关功能的记录. 相关的可以去我的博客/RabbitM ...

  5. BZOJ3118 Orz the MST 【单纯形 + 生成树】

    题目链接 BZOJ3118 题解 少有的单纯形好题啊 我们先抽离出生成树 生成树中的边只可能减,其它边只可能加 对于不在生成树的边,其权值一定要比生成树中其端点之间的路径上所有的边都大 然后就是一个最 ...

  6. .net连接ORACLE数据库

    这段时间维护客户的一个系统,该系统使用的是ORACLE数据库,之前开发的时候用的都是MSSQL,并没有使用过ORACLE.这两种数据库虽然都是关系型数据库,但是具体的操作大有不同,这里作下记录. 连接 ...

  7. Java -- JDBC 学习--通过 ResultSet 执行查询操作

    ResultSet: 结果集. 封装了使用 JDBC 进行查询的结果. 1. 调用 Statement 对象的 executeQuery(sql) 可以得到结果集. 2. ResultSet 返回的实 ...

  8. 使用fiddler模拟http请求

    概述  与httpwath相比,fiddler能模拟http请求.能断点调试.http分析统计吸引了我,使用之后感觉这个工具非常不错,这篇文章只单介绍一下fiddler工作原理,简单介绍一下它的重要功 ...

  9. Git中设置代理和取消代理

    设置Socks5代理 git config --global http.proxy 'socks5://127.0.0.1:1080' && git config --global h ...

  10. A1053. Path of Equal Weight

    Given a non-empty tree with root R, and with weight Wi assigned to each tree node Ti. The weight of ...