BZOJ 4247: 挂饰 动态规划
按照挂件数量排序,然后做一个 DP 就好了.
code:
#include <bits/stdc++.h>
#define ll long long
#define N 2003
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
ll f[N];
struct node {
int a,b;
}s[N];
bool cmp(node x,node y) {
return x.a>y.a;
}
int main()
{
// setIO("input");
int i,j,n;
ll ans=0;
memset(f,-0x3f,sizeof(f)),f[0]=f[1]=0;
scanf("%d",&n);
for(i=1;i<=n;++i) {
scanf("%d%d",&s[i].a,&s[i].b);
}
sort(s+1,s+1+n,cmp);
for(i=1;i<=n;++i) {
if(s[i].a!=0) {
for(j=n;j>=1;--j) {
int v=min(j+s[i].a-1,n);
f[v]=max(f[v],f[j]+s[i].b);
ans=max(ans,f[v]);
}
}
else {
for(j=1;j<=n;++j) f[j-1]=max(f[j-1],f[j]+s[i].b),ans=max(ans,f[j-1]);
}
}
printf("%lld\n",ans);
return 0;
}
BZOJ 4247: 挂饰 动态规划的更多相关文章
- BZOJ 4247 挂饰 背包DP
4247: 挂饰 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/problem.php?id ...
- BZOJ 4247 挂饰(背包问题)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4247 [题目大意] JOI君有N个装在手机上的挂饰,编号为1...N. JOI君可以将 ...
- BZOJ 4247 挂饰 01背包
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4247 JOI君有N个装在手机上的挂饰,编号为1...N. JOI君可以将其中的一些装在手机 ...
- bzoj 4247: 挂饰【dp】
bzoj上访问负下标会跑到奇怪的地方-- 其实可以滚动数组优化,但是我看能过就懒得改了 设f[i][j]为已经算了前i个挂饰,当前有j个空的钩子,转移就是f[i][j]=max(f[i-1][j],f ...
- BZOJ 4247: 挂饰 题解
Description JOI君有N个装在手机上的挂饰,编号为1...N. JOI君可以将其中的一些装在手机上. JOI君的挂饰有一些与众不同--其中的一些挂饰附有可以挂其他挂件的挂钩.每个挂件要么直 ...
- BZOJ 4247: 挂饰
背包裸题 #include<cstdio> #include<algorithm> using namespace std; int F[2005]; struct node{ ...
- bzoj 4247挂饰
背包????不会... #include<bits/stdc++.h> #define INF 0x7fffffff #define LL long long #define N 1000 ...
- bzoj千题计划197:bzoj4247: 挂饰
http://www.lydsy.com/JudgeOnline/problem.php?id=4247 先把挂饰按挂钩数量从大到小排序 dp[i][j]前i个挂饰,剩下j个挂钩的最大喜悦值 分挂和不 ...
- bzoj4247: 挂饰(背包dp)
4247: 挂饰 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1136 Solved: 454[Submit][Status][Discuss] ...
随机推荐
- Dubbo 服务 IP 注册错误踩坑经历
个人博客地址 studyidea.cn,点击查看更多原创文章 踩坑 公司最近新建一个机房,需要将现有系统同步部署到新机房,部署完成之后,两地机房同时对提供服务.系统架构如下图: 这个系统当前对外采用 ...
- One Stage目标检测
在计算机视觉中,目标检测是一个难题.在大型项目中,首先需要先进行目标检测,得到对应类别和坐标后,才进行之后的各种分析.如人脸识别,通常是首先人脸检测,得到人脸的目标框,再对此目标框进行人脸识别.如果该 ...
- Python 元类 - Metaclasses
Python 元类 - Metaclasses 默认情况下儿, classes 是有 type() 构造的. 类的结构体在一个新的 namespace 被执行, 类的名字 class name 绑定( ...
- 使用Unicode(宽字节字符集);多字节字符集中定义宽字节变量
2012-03-25 14:54 (分类:计算机程序) 2.2 宽字符和C 宽字符不一定是Unicode.Unicode是宽字符集的一种.然而,因为本书的焦点是Windows而不是C执行的理论,所以书 ...
- 在Linux实例上自动安装并运行VNC Server
#!/bin/bash ######################################### #Function: install vnc server #Usage: bash ins ...
- Unable to update index for nexus-publish | http://ip:port/repository/maven-public/
问题描述:Unable to update index for nexus-publish | http://ip:port/repository/maven-public/ 解决方案:进入工作空间. ...
- [Redis-CentOS7]Redis字符串操作(二)
登录Redis # redis-cli 127.0.0.1:6379> 添加字符串 EX 超期时间60s 127.0.0.1:6379> set username 'leoshi' OK ...
- React之this绑定
一.首先看一下没有绑定this的情况 class App extends React.Component{ constructor(props){ super(props) console.log(' ...
- window.location操作url对象
URL即:统一资源定位符 (Uniform Resource Locator, URL) 完整的URL由这几个部分构成:scheme://host:port/path?query#fragment s ...
- 第三篇 SpringBoot整合log4j2详解
源代码:https://pan.baidu.com/s/1d1Lwv1gIvVNltIKVWeEseA 提取码:wff0 SpringBoot整合Log4j2步骤: 1.删除spring-boot-s ...