bzoj千题计划197:bzoj4247: 挂饰
http://www.lydsy.com/JudgeOnline/problem.php?id=4247
先把挂饰按挂钩数量从大到小排序
dp[i][j]前i个挂饰,剩下j个挂钩的最大喜悦值
分挂和不挂转移
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm> using namespace std; #define N 2011 int dp[N+][N]; struct node
{
int sum,val;
}e[N]; void read(int &x)
{
x=; int f=; char c=getchar();
while(!isdigit(c)) { if(c=='-') f=-; c=getchar(); }
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
x*=f;
} bool cmp(node p,node q)
{
return p.sum>q.sum;
} int main()
{
int n;
read(n);
for(int i=;i<=n;++i)
{
read(e[i].sum);
read(e[i].val);
}
sort(e+,e+n+,cmp);
memset(dp,-,sizeof(dp));
int inf=dp[][];
dp[][]=;
for(int i=;i<=n;++i)
for(int j=;j<=n;++j)
if(dp[i][j]!=inf)
{
dp[i+][min(n,j-+e[i].sum)]=max(dp[i+][min(n,j-+e[i].sum)],dp[i][j]+e[i].val);
dp[i+][j]=max(dp[i+][j],dp[i][j]);
}
int ans=;
for(int i=;i<=n;++i) ans=max(ans,dp[n+][i]);
cout<<ans;
}
4247: 挂饰
Time Limit: 10 Sec Memory Limit: 256 MB
Submit: 1253 Solved: 507
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
0 4
2 -2
1 -1
0 1
0 3
Sample Output
HINT
Source
bzoj千题计划197:bzoj4247: 挂饰的更多相关文章
- bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块
http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...
- bzoj千题计划196:bzoj4826: [Hnoi2017]影魔
http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...
- bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪
http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...
- bzoj千题计划177:bzoj1858: [Scoi2010]序列操作
http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...
- bzoj千题计划317:bzoj4650: [Noi2016]优秀的拆分(后缀数组+差分)
https://www.lydsy.com/JudgeOnline/problem.php?id=4650 如果能够预处理出 suf[i] 以i结尾的形式为AA的子串个数 pre[i] 以i开头的形式 ...
- bzoj千题计划304:bzoj3676: [Apio2014]回文串(回文自动机)
https://www.lydsy.com/JudgeOnline/problem.php?id=3676 回文自动机模板题 4年前的APIO如今竟沦为模板,,,╮(╯▽╰)╭,唉 #include& ...
- bzoj千题计划292:bzoj2244: [SDOI2011]拦截导弹
http://www.lydsy.com/JudgeOnline/problem.php?id=2244 每枚导弹成功拦截的概率 = 包含它的最长上升子序列个数/最长上升子序列总个数 pre_len ...
- bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机
http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...
- bzoj千题计划250:bzoj3670: [Noi2014]动物园
http://www.lydsy.com/JudgeOnline/problem.php?id=3670 法一:KMP+st表 抽离nxt数组,构成一棵树 若nxt[i]=j,则i作为j的子节点 那么 ...
随机推荐
- eclipse + maven + org.glassfish.jersey 创建 webapi
org.glassfish.jersey 和 com.sun.jersey 的区别是,jersy version 2 之前是 com.sun.jersy, 之后改名为 org.glassfish.je ...
- Jmeter(二十二)_jenkins配置gitlab插件与ant插件
Docker部署接口自动化持续集成环境第四步,代码上传到远程仓库! 接上文:脚本上传Gitlab 服务器中的Jenkins通过Gitlab插件读取远程Git远程仓库中的代码,然后通过ant插件进行构建 ...
- 能帮我们学习吉他的音乐软件——Guitar Pro
Guitar Pro是一款十分好用的吉他软件,也是目前广大音乐爱好者最喜欢的多音轨的音谱编辑软件.支持MIDI.MusicXML.PTB.GTP等多种格式文件的导入/导出. Guitar Pro 7. ...
- PAT甲题题解-1031. Hello World for U (20)-字符串处理,水
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
- eclipse实现热部署和热启动
不用每次修改一个class文件就要重启tomcat这么麻烦: http://blog.csdn.net/fuzhongyu2/article/details/52073050
- “Linux内核分析”实验三报告
构造一个简单的Linux系统 张文俊+原创作品转载请注明出处+<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-10000290 ...
- Linux内核分析——第五周学习笔记
第五周 扒开系统调用的“三层皮”(下) 一.知识点总结 (一)给MenuOS增加time和time-asm命令 在实验楼中,首先 强制删除menu (rm menu -rf) 重新克隆一个新版本的me ...
- [转]JAVA 在main中访问内部类、方法等
1.使用静态的属性.方法.内部类 class A { static int i = 1; // A 类的静态属性 static void outPut() // A 类的静态方法 { System.o ...
- Bean的加载
ClassPathXmlApplicationContext存储内容 为了更理解ApplicationContext,拿一个实例ClassPathXmlApplicationContext举例,看一下 ...
- 安全相关论文--Security and Dependability
安全相关论文--Security and Dependability 所参考的文献来自于Kreutz D, Ramos F M V, Esteves Verissimo P, et al. Softw ...