//因为同一点结束的时间段会有多个,这里没考虑;
//无限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】的更多相关文章

  1. 「kuangbin带你飞」专题十二 基础DP

    layout: post title: 「kuangbin带你飞」专题十二 基础DP author: "luowentaoaa" catalog: true tags: mathj ...

  2. 基础dp

    队友的建议,让我去学一学kuangbin的基础dp,在这里小小的整理总结一下吧. 首先我感觉自己还远远不够称为一个dp选手,一是这些题目还远不够,二是定义状态的经验不足.不过这些题目让我在一定程度上加 ...

  3. 基础DP(初级版)

    本文主要内容为基础DP,内容来源为<算法导论>,总结不易,转载请注明出处. 后续会更新出kuanbin关于基础DP的题目...... 动态规划: 动态规划用于子问题重叠的情况,即不同的子问 ...

  4. hdu 5586 Sum 基础dp

    Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Desc ...

  5. hdu 4055 Number String (基础dp)

    Number String Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  6. 训练指南 UVA - 10917(最短路Dijkstra + 基础DP)

    layout: post title: 训练指南 UVA - 10917(最短路Dijkstra + 基础DP) author: "luowentaoaa" catalog: tr ...

  7. 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP)

    layout: post title: 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP) author: "luowentaoaa" catalog: true ...

  8. M - 基础DP

    M - 基础DP Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Descriptio ...

  9. lightoj1004【基础DP】

    从低端到顶端求个最大值: 思路: 基础DP,递推 #include<cstdio> #include<queue> #include<map> #include&l ...

随机推荐

  1. Solidworks做镜像 导致厚度为零的几何体怎么办

    如下图所示,我想把1,2,3,4架子做一个镜像,但是提示错误   貌似只能用镜像实体,并且取消勾选"合并实体"    

  2. sql 导入数据库 出现乱码问题 解决办法 设置 --default-character-set=utf8

    mysql -u root -p --default-character-set=utf8 use dbname source /root/newsdata.sql

  3. MySQL和MongoDB的性能测试

    软硬件环境 MySQL版本:5.1.50,驱动版本:5.1.6(最新的5.1.13有很多杂七杂八的问题) MongoDB版本:1.6.2,驱动版本:2.1 操作系统:Windows XP SP3(这个 ...

  4. 【转载】“菜”鸟理解.NET Framework(CLI,CLS,CTS,CLR,FCL,BCL)

    既然要学.NET,就要先认识认识她,我不喜欢大段大段文字的东西,自己通过理解,画个图,来看看.NET的沉鱼落雁,闭月羞花之容. 最下层蓝色部分是.NET Framework的基础,也是所有应用软件的基 ...

  5. mac系统下为emacs设置中文字体,解决乱码问题

    近期换了个系统,如今用mac系统. 当打开emacs后,中文支持的不是非常好.有的地方能显示.在.el文件的凝视里显示为口口口口口口口口这种框.例如以下图所看到的 找了半天.是由于中文字体的问题.仅仅 ...

  6. Linux下mount FreeBSD分区

    假设须要从第二块硬盘复制文件.该硬盘格式化为UFS 2文件系统.怎样mount 由FreeBSD创建的UFS 2文件系统到Ubuntu系统上呢? UFS文件系统广泛的使用在不同的操作系统(比如:HP- ...

  7. Jenkins+maven+SVN+Tomcat部署过程

    一.下载地址 应首先确认安装了JDK: Jenkins下载地址:http://mirrors.shu.edu.cn/jenkins/windows-stable/jenkins-2.107.3.zip ...

  8. 如何在外部采用AES-128对HLS的TS流进行加密

    http://www.wowza.cn/hls/howToSecureHlsByAes128External

  9. UIPanGestureRecognizer上下左右滑动方向推断算法

    CGFloat const gestureMinimumTranslation = 20.0; typedef enum :NSInteger { kCameraMoveDirectionNone, ...

  10. python day-3 基本数据类型

    1. 编码 1. 最早的计算机编码是ASCII. 美国人创建的. 包含了英文字母(大写字母, 小写字母). 数字, 标点等特殊字符!@#$% 128个码位 2**7 在此基础上加了一位 2**8 8位 ...