//因为同一点结束的时间段会有多个,这里没考虑;
//无限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. android_checkbox_dialog 设计 是不是要开起 默认不提示对话框

    android_checkbox_dialog设计是不是开起默认不提示 package com.example.android_checkbox_dialog; import android.app. ...

  2. 一道有关switch-case题目

    一道有关switch-case题目 /** * * @title:SwitchCase.java * @Package:com.you.hbxs.model * @Description:<h3 ...

  3. win10安装Anaconda+TensorFlow+配置PyCharm

    其实很简单,我这里也只是记录一下而已. 第一大坑:anaconda必须安装4.2以前的版本,不能安装4.3以后的 版本:满满的血泪史 因为我们需要安装自带的python必须是3.5,才可以调用Tens ...

  4. 2016/06/10 日历插件 Datepicker

    显示效果: <!doctype html> <html lang="en"> <head> <meta charset="utf ...

  5. 常见的页面效果,相关的js代码

    1.焦点图 $(document).ready(function(){ var i=0; var autoChange= setInterval(function(){ if(i<$(" ...

  6. PLSQL 安装说明

    PLSQL安装说明. 1.安装oracle 11g ,2030端口设置防火墙例外.2.PLSQL Developer 9.0.0.1601是绿色版,复制到本地即可.3.PLSQL->Tools- ...

  7. jquery清空div里所有input输入框的值

    $("#divId input").val("");

  8. React引入,运行

    1.引入 <script src="https://cdn.bootcss.com/react/15.5.4/react.min.js"></script> ...

  9. Apriori算法实例

    Apriori算法与实例 R. Agrawal 和 R. Srikant于1994年在文献[2]中提出了Apriori算法,该算法的描述如下: 下面是一个具体的例子,最开始数据库里有4条交易,{A.C ...

  10. damon

    不管是否有-f参数,最终程序都会进入 fuse_loop_mt 循环中,在helper.c的fuse_main_common函数中. 1. 有-f参数.这种情况下fuse_setup_common函数 ...