Surf
Now that you've come to Florida and taken up surng, you love it! Of course, you've realized that
if you take a particular wave, even if it's very fun, you may miss another wave that's just about
to come that's even more fun. Luckily, you've gotten excellent data for each wave that is going to
come: you'll know exactly when it will come, how many fun points you'll earn if you take it, and
how much time you'll have to wait before taking another wave. (The wait is due to the fact that
the wave itself takes some time to ride and then you have to paddle back out to where the waves
are crashing.) Obviously, given a list of waves, your goal will be to maximize the amount of fun
you could have.
Consider, for example, the following list of waves:
Minute Fun points Wait time
2 80 9
8 50 2
10 40 2
13 20 5
In this example, you could take the waves at times 8, 10 and 13 for a total of 110 fun points. If
you take the wave at time 2, you can't ride another wave until time 11, at which point only 20 fun
points are left for the wave at time 13, leaving you with a total of 100 fun points. Thus, for this
input, the correct answer (maximal number of fun points) is 110.
Given a complete listing of waves for the day, determine the maximum number of fun points
you could earn.
Input
The rst line of input contains a single integer n (1 n 300;000), representing the total number
of waves for the day. The ith line (1 i n) that follows will contain three space separated
integers: mi, fi, and wi, (1 mi; fi;wi 106), representing the time, fun points, and wait time
of the ith wave, respectively. You can ride another wave occurring at exactly time mi + wi after
taking the ith wave. It is guaranteed that no two waves occur at the same time. The waves may
not be listed in chronological order.
2015 Pacic Northwest Region Programming Contest|Division 2 17
Output
Print, on a single line, a single integer indicating the maximum amount of fun points you can get
riding waves.
Sample Input 
4
8 50 2
10 40 2
2 80 9
13 20 5

Sample Output
110

Sample Input
10
2079 809484 180
8347 336421 2509
3732 560423 483
2619 958859 712
7659 699612 3960
7856 831372 3673
5333 170775 1393
2133 989250 2036
2731 875483 10
7850 669453 842

Sample Output

3330913

题目链接:http://codeforces.com/gym/100819

解法一:正常dp  优先队列转移

/* ***********************************************
Author :guanjun
Created Time :2016/8/13 13:48:58
File Name :voh.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 300100
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std; struct Node{
ll beg;
ll end;
ll val;
int id;
}nod[maxn]; struct cmp{
bool operator()(Node a,Node b){
if(a.end==b.end) return a.beg<b.beg;
return a.end>b.end;
}
}; bool cmp1(Node a,Node b){
if(a.beg==b.beg)return a.end<b.end;
return a.beg<b.beg;
}
int n;
ll dp[maxn][];
priority_queue<Node,vector<Node>,cmp>q;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
while(cin>>n){
ll x;
for(int i=;i<=n;i++){
scanf("%lld %lld %lld",&nod[i].beg,&nod[i].val,&x);
nod[i].end=nod[i].beg+x;
}
sort(nod+,nod++n,cmp1);
int sum=;
for(int i=;i<=n;i++)nod[i].id=i;
while(!q.empty())q.pop();
Node u,v;
ll Max=;
cle(dp);
for(int i=;i<=n;i++){
v=nod[i];
q.push(v);
while(!q.empty()){
u=q.top();
if(u.end<=v.beg){
q.pop();
Max=max(Max,dp[u.id][]);
}
else break;
}
dp[i][]=Max+nod[i].val;
dp[i][]=max(dp[i-][],dp[i-][]);
}
printf("%lld\n",max(dp[n][],dp[n][]));
}
return ;
}

解法二:依据时间dp

/* ***********************************************
Author :guanjun
Created Time :2016/8/13 21:19:02
File Name :a.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 1000010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
int x,y;
};
struct cmp{
bool operator()(Node a,Node b){
if(a.x==b.x) return a.y> b.y;
return a.x>b.x;
}
}; bool cmp(int a,int b){
return a>b;
}
ll dp[*maxn];
int v[maxn];
int t[maxn],n;
int main()
{
#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
cin>>n;
int x;
for(int i=;i<n;i++){
scanf("%d",&x);
scanf("%d %d",&v[x],&t[x]);
}
for(int i=maxn-;i>=;i--){
dp[i]=dp[i+];
if(v[i])
dp[i]=max(dp[i],v[i]+dp[i+t[i]]);
}
printf("%lld\n",dp[]);
return ;
}

2015-2016 ACM-ICPC Pacific Northwest Regional Contest (Div. 2) S Surf的更多相关文章

  1. 2018 ICPC Pacific Northwest Regional Contest I-Inversions 题解

    题目链接: 2018 ICPC Pacific Northwest Regional Contest - I-Inversions 题意 给出一个长度为\(n\)的序列,其中的数字介于0-k之间,为0 ...

  2. 2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)

    2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) 思路: A Exam 思路:水题 代码: #include<bits ...

  3. Contest Setting 2018 ICPC Pacific Northwest Regional Contest dp

    题目:https://vj.69fa.cn/12703be72f729288b4cced17e2501850?v=1552995458 dp这个题目网上说是dp+离散化这个题目要对这些数字先处理然后进 ...

  4. 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) Solution

    A:Alphabet Solved. 签. #include<bits/stdc++.h> using namespace std; ]; ]; int main(){ scanf(); ...

  5. 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 2) 题解

    [题目链接] A - Alphabet 最长公共子序列.保留最长公共子序列,剩余的删除或者补足即可. #include <bits/stdc++.h> using namespace st ...

  6. 2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) Solution

    A:Exam Solved. 温暖的签. #include<bits/stdc++.h> using namespace std; ; int k; char str1[maxn], st ...

  7. 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) K Tournament Wins

    题目链接:http://codeforces.com/gym/101201 /* * @Author: lyucheng * @Date: 2017-10-22 14:38:52 * @Last Mo ...

  8. 2017-2018 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)

    A. Odd Palindrome 所有回文子串长度都是奇数等价于不存在长度为$2$的偶回文子串,即相邻两个字符都不同. #include<cstdio> #include<cstr ...

  9. 2017-2018 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) B - Enlarging Enthusiasm dp好题

    B - Enlarging Enthusiasm 感觉做到过好多的dp题都会和单调性结合在一起. 思路:dp[ s ][ pre ][ res ] 表示的是已选择了s,上一个是pre, 还有res 的 ...

随机推荐

  1. cc.AudioSource

    cc.AudioSource1:AudioSource组件是音频源组件, 发出声音的源头2: AudioSource组件面板: clip: 声源的播放的音频对象: AudioClip, mp3, wa ...

  2. 题解 洛谷P4035/BZOJ1013【[JSOI2008]球形空间产生器】

    题目链接在这QvQ "你要求出这个n维球体的球心坐标",这使我想到的解方程...... 先假设n=2,这是一个二维平面.设圆心的坐标为\((x,y)\),有两个坐标\((a_1,b ...

  3. 题解 P1967 货车运输

    题目描述 A 国有 n 座城市,编号从 1 到 n,城市之间有 m 条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有 q 辆货车在运输货物,司机们想知道每辆车在不超过车辆限重的情况下,最多能 ...

  4. 笔试算法题(12):整数的string到int转换 & 两个栈实现队列

    出题:将输入的表示整数的字符串转变为对应的整数值: 分析: 每当右边增加一位,说明之前的sum应该高一个数量级,所以*10.由于这两个实现仅仅考虑正规的.正整数输入,所以需要一个Wrapper函数,其 ...

  5. MySQL与MyBatis中的查询记录

    1.时间段查询 MySQL:select * from table where ctime >= CURDATE() and ctime <DATE_SUB(CURDATE(),INTER ...

  6. 初识 Spring 框架

    初识 Spring 框架可以帮助我们构建规范的.优秀的应用程序,简化烦琐的编码过程. Spring 是一个非常著名的轻量级的企业级开源框架,Spring 的目标是使 Java EE 更易用并促进良好的 ...

  7. 常见的Redis问题?

    Redis的那些最常见面试问题[转] 1.什么是redis? Redis 是一个基于内存的高性能key-value数据库. 2.Reids的特点 Redis本质上是一个Key-Value类型的内存数据 ...

  8. Python操作Redis、Memcache

       今天主要介绍如何通过python来对Redis和memcache进行操作,下面开始今天的内容: 一.Memcached操作 Memcached是一个高性能的分布式内存对象缓存系统,用于动态Web ...

  9. es6(var,let,const,set,map,Array.from())

    1.变量声明--var,const,let 1.1 var - (全局作用域,局部作用域)会有变量提升 //第一个小例子 <script> var num = 123; function ...

  10. hihoCoder#1114 小Hi小Ho的惊天大作战:扫雷·一

    原题地址 回溯+搜索 枚举每个位置上能否放地雷,当第i个位置枚举完成后,第i-1个位置的情况就确定了,此时,检查第i-1个位置是否满足要求,即左右间隔为1的范围内地雷数是否等于申明数字,如果满足条件, ...