POJ3616【基础DP】
//因为同一点结束的时间段会有多个,这里没考虑;
//无限wa;
const int N=1e6+7;
int b[N];
LL a[N];
LL dp[N];
struct asd{
int s;
int t;
LL w;
};
asd q[N];
bool cmp(asd z,asd x)
{
if(z.t<x.t)
return 1;
return 0;
}
int main()
{
int n,m,r;
while(~scanf("%d%d%d",&n,&m,&r))
{
int s,t;
LL w;
for(int i=0;i<m;i++){
scanf("%d%d%lld",&s,&t,&w);
q[i].s=s;
q[i].t=t;
q[i].w=w;
}
sort(q,q+m,cmp);
memset(a,0,sizeof(a));
for(int i=0;i<m;i++){
a[q[i].t]=q[i].w;
b[q[i].t]=q[i].s;
}
memset(dp,0,sizeof(dp));
int x;
for(int i=1;i<=n;i++)
{
x=b[i]-r;
if(x>=0){
dp[i]=max(dp[i-1],dp[x]+a[i]);
}
else{
dp[i]=max(a[i],dp[i-1]);
}
}
/* for(int i=1;i<=n;i++)
printf("%lld ",dp[i]);
puts("");*/
printf("%lld\n",dp[n]);
}
return 0;
}
/*
12 4 2
1 2 8
10 12 19
3 5 24
7 10 31
12 4 2
1 2 8
10 12 19
3 6 24
7 10 31
*/
后面想的是那我for一下前面的,然后找到有那个截止点的数据,然后找一个最优的。后来没有搞成n+m,就理应吃T了一发。
已AC;
#include<iostream>
#include<cstdio>
#include<math.h>
#include<queue>
#include<map>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
//因为同一点结束的时间段会有多个,这里没考虑;
//无限wa;
const int N=1e6+7;
int b[N];
LL a[N];
LL dp[N];
struct asd{
int s;
int t;
LL w;
};
asd q[N];
bool cmp(asd z,asd x)
{
if(z.t<x.t)
return 1;
return 0;
}
int main()
{
int n,m,r;
while(~scanf("%d%d%d",&n,&m,&r))
{
int s,t;
LL w;
for(int i=0;i<m;i++){
scanf("%d%d%lld",&s,&t,&w);
q[i].s=s;
q[i].t=t;
q[i].w=w;
}
memset(dp,0,sizeof(dp));
for(int i=0;i<m;i++){
dp[q[i].t]=max(q[i].w,dp[q[i].t]);
}
sort(q,q+m,cmp);
int x;
int i,j=0;
for(i=1;i<=n;i++){
dp[i]=max(dp[i],dp[i-1]);
for(;j<m;){
if(q[j].t==i){
x=q[j].s-r;
if(x<0) x=0;
dp[i]=max(dp[i],dp[x]+q[j].w);
j++;
}
else
break;
}
}
/* for(int i=1;i<=n;i++){
printf("%d ",dp[i]);
}
puts("");*/
printf("%d\n",dp[n]);
}
return 0;
}
/*
12 4 2
1 2 8
10 12 19
3 5 24
7 10 31
12 4 2
1 2 8
10 12 19
3 6 24
7 10 31
*/
POJ3616【基础DP】的更多相关文章
- 「kuangbin带你飞」专题十二 基础DP
layout: post title: 「kuangbin带你飞」专题十二 基础DP author: "luowentaoaa" catalog: true tags: mathj ...
- 基础dp
队友的建议,让我去学一学kuangbin的基础dp,在这里小小的整理总结一下吧. 首先我感觉自己还远远不够称为一个dp选手,一是这些题目还远不够,二是定义状态的经验不足.不过这些题目让我在一定程度上加 ...
- 基础DP(初级版)
本文主要内容为基础DP,内容来源为<算法导论>,总结不易,转载请注明出处. 后续会更新出kuanbin关于基础DP的题目...... 动态规划: 动态规划用于子问题重叠的情况,即不同的子问 ...
- hdu 5586 Sum 基础dp
Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Desc ...
- hdu 4055 Number String (基础dp)
Number String Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 训练指南 UVA - 10917(最短路Dijkstra + 基础DP)
layout: post title: 训练指南 UVA - 10917(最短路Dijkstra + 基础DP) author: "luowentaoaa" catalog: tr ...
- 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP)
layout: post title: 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP) author: "luowentaoaa" catalog: true ...
- M - 基础DP
M - 基础DP Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descriptio ...
- lightoj1004【基础DP】
从低端到顶端求个最大值: 思路: 基础DP,递推 #include<cstdio> #include<queue> #include<map> #include&l ...
随机推荐
- HDU 4902 Nice boat 线段树+离线
据说暴力也过了.还傻逼地写了这么长. . . #include <stdio.h> #include <string.h> #include <math.h> #i ...
- 新生入学V3.0颗粒归仓
新生入学系统V3.0接近尾声.每次做项目都有不一样的收获.V1.0,V2.0主要是熟悉了整个项目流程是怎样进行的,可行性分析--需求分析(原型图Axure)--实体设计(PD)--类图时序图(EA)- ...
- virtual member functions(单一继承情况)
virtual member functions的实现(就单一继承而言): 1.实现:首先会给有多态的class object身上增加两个members:一个字符串或数字便是class的类型,一个是指 ...
- c#中的多态 c#中的委托
C#中的多态性 相信大家都对面向对象的三个特征封装.继承.多态很熟悉,每个人都能说上一两句,但是大多数都仅仅是知道这些是什么,不知道CLR内部是如何实现的,所以本篇文章主要说说多态性 ...
- 疯狂Java学习笔记(77)-----------凝视注意事项
代码凝视,能够说是比代码本身更重要.这里有一些方法能够确保你写在代码中的凝视是友好的: 不要反复阅读者已经知道的内容 能明白说明代码是做什么的凝视对我们是没有帮助的. // If the color ...
- Beijing Bus
Search: http://bjgj.aibang.com:8899 https://github.com/sp-chenyang/bus https://github.com/leavind/Co ...
- Apache Qpid 高可用集群
一.RHCS RHCS是Red Hat Cluster Suite(红帽子集群套件)的缩写.RHCS是一个功能完备的集群应用解决方案,它从应用的前端访问到后端的数据存储都提供了一个行之有效的集群架构实 ...
- SignatureDoesNotMatch REST接口 在任何时间、任何地点、任何互联网设备上 在Header中包含签名
PutObject_关于Object操作_API 参考_对象存储 OSS-阿里云 https://help.aliyun.com/document_detail/31978.html OSS API ...
- Mysql常见函数
一.单行函数 1.字符函数 concat拼接 substr截取子串 upper转换成大写 lower转换成小写 trim去前后指定的空格和字符 ltrim去左边空格 rtrim去右边空格 replac ...
- GPS常见故障
当出现故障时,依据可能原因进行排查. 下表列举典型故障及调试方法 现象 root cause 检查 实验 GPS无法开启/无法搜星 软件配置错误 SW 相关配置(如GPIO等) 录制mobile ...