传送门

题意:\(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. BZOJ5251 八省联考2018劈配(网络流)

    劈配,匹配,网络流.那么考虑怎么跑网络流. 先看第一问.首先套路的建出超源超汇.不用想也知道导师向汇连容量为战队人数上限的边.特别地,给出局也建一个点,向汇连容量inf的边(似乎没有必要).对于一个新 ...

  2. 自学Linux Shell4.1-监测程序ps top kill

    点击返回 自学Linux命令行与Shell脚本之路 4.1-监测程序ps top kill 1. PS命令 linux中的ps命令是Process Status的缩写.ps命令用来列出系统中当前运行的 ...

  3. 【BZOJ3456】城市规划(生成函数,多项式运算)

    [BZOJ3456]城市规划(生成函数,多项式运算) 题面 求\(n\)个点的无向连通图个数. \(n<=130000\) 题解 \(n\)个点的无向图的个数\(g(n)=2^{C_n^2}\) ...

  4. Shell基础知识(一)

    教程链接:shell从入门到入门 这个网站还有其他教程,可以尝试下看看.   普及类文章:bash/cmd/dos之间有什么区别与联系 >> bash是Linux下的一个shell应用程序 ...

  5. ECMAScript 6 -- 数组的解构赋值

    模式匹配:只要等号两边的模式相同,左边的变量就会被赋予对应的值. let [a, b, c] = [1, 2, 3]; 嵌套数组进行解构: let [foo, [[bar], baz]] = [1, ...

  6. 在Android中通过Intent使用Bundle传递对象

    IntentBundle传递对象SerializableParcelable Android开发中有时需要在应用中或进程间传递对象,下面详细介绍Intent使用Bundle传递对象的方法.被传递的对象 ...

  7. SQLite 学习笔记(一)

      (1)创建数据库   在命令行中切换到sqlite.exe所在的文件夹   在命令中键入sqlite3 test.db;即可创建了一个名为test.db的数据库   由于此时的数据库中没有任何表及 ...

  8. 洛谷P4112 最短不公共子串

    题意: 下面,给两个小写字母串A,B,请你计算: (1) A的一个最短的子串,它不是B的子串 (2) A的一个最短的子串,它不是B的子序列 (3) A的一个最短的子序列,它不是B的子串 (4) A的一 ...

  9. The 2016 ACM-ICPC Asia Beijing Regional Contest E - What a Ridiculous Election

    https://vjudge.net/contest/259447#problem/E bfs,k个限制条件以数组的额外k维呈现. #include <bits/stdc++.h> usi ...

  10. jenkins Pipeline 使用

    说明 Jenkins pipeline 是一套插件,支持将连续输送管道实施和整合到Jenkins.Pipeline提供了一组可扩展的工具,用于通过管道DSL为代码创建简单到复杂的传送流水线.他目前支持 ...