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 ;
}

最新文章

  1. JS组件系列——表格组件神器:bootstrap table(三:终结篇,最后的干货福利)
  2. Spring学习笔记
  3. C# 反射范范的理解下
  4. 14. javacript高级程序设计-表单
  5. JavaScript - BOM
  6. nginx location 匹配顺序
  7. DOM4J解析xml案例
  8. 在div中设置文字与内部div垂直居中
  9. Asp.Net 之 使用Form认证实现用户登录 (LoginView的使用)
  10. 多线程(Thread),其实很简单!
  11. 利用汇编查看C++函数调用
  12. 在Win7的IIS上搭建FTP服务及用户授权——转载!!
  13. 权限系统设计实现MVC4 + WebAPI + EasyUI + Knouckout
  14. iOS 内存泄漏
  15. 201521123022 《Java程序设计》 第五周学习总结
  16. ibv_open_device()函数
  17. LNMP环境下搭建wordpress
  18. vim学习纪要
  19. SP8791 DYNALCA - Dynamic LCA 解题报告
  20. sockaddr_in 与 in_addr的区别

热门文章

  1. List&lt;&gt; 集合 删除指定行
  2. C51 keil 注意事项
  3. 编程数学-∑(求和符号)-Sigma
  4. php.ini中date.timezone设置分析
  5. [BZOJ3196] [Tyvj1730] 二逼平衡树(线段树 套 Splay)
  6. noip模拟赛 补兵
  7. js判断对象是否为空对象的几种方法
  8. android开发里跳过的坑——“org.apache.http.message.BasicHeaderValueFormatter.INSTANCE”错误
  9. hdu - 1068 Girls and Boys (二分图最大独立集+拆点)
  10. hihocoder1496(高维前缀和)