题目:

 Now that you’ve come to Florida and taken up surfing, 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.

题意:

大体上就是给你n组数据,区间开始,权值的大小,区间持续时间(即区间的结束时间),选择其中的区间,使其最终权值最大。

详细题意自己翻吧。

思路:

贪心的思想,也有点像背包,首先将n个区间按结束时间排序,然后背包每个区间选与不选使其最终权值最大。

具体看代码。

代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <cstdlib>
using namespace std;
#define is_lower(c) (c>='a' && c<='z')
#define is_upper(c) (c>='A' && c<='Z')
#define is_alpha(c) (is_lower(c) || is_upper(c))
#define is_digit(c) (c>='0' && c<='9')
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define IO ios::sync_with_stdio(0);\
    cin.tie();\
    cout.tie();
#define For(i,a,b) for(int i = a; i <= b; i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
const ll inf=0x3f3f3f3f;
;
const ll inf_ll=(ll)1e18;
const ll maxn=100005LL;
const ll mod=1000000007LL;
;
struct node {
    int s,e;
    int score;
}r[];
bool cmp(node a,node b) {
    return a.e <b.e;
}
];
int main() {
    int T;
    scanf("%d",&T);
    ; i <= T; i++){
        int x ;
        scanf("%d%d%d",&r[i].s,&r[i].score,&x);
        r[i].e = r[i].s + x;
    }
    sort(r+,r+T+,cmp);
    ; i <= T;i++){
        dp[r[i].e] = max(dp[r[i].s]+r[i].score,dp[r[i].e]);
        ; j <= r[i+].e;j++)  //此循环代表若不选它的下一区间权值的最大值。
            dp[j] = dp[r[i].e];
    }
    printf("%lld\n",dp[r[T].e]);
}

/*
4
8 50 2
10 40 2
2 80 9
13 20 5


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
*/

 

codeforces 某套题s : surf(贪心 || 动态规划)的更多相关文章

  1. codeforces 1064套题

    a题:题意就是问,3个数字差多少可以构成三角形 思路:两边之和大于第三遍 #include<iostream> #include<algorithm> using namesp ...

  2. 第46套题【STL】【贪心】【递推】【BFS 图】

    已经有四套题没有写博客了.今天改的比较快,就有时间写.今天这套题是用的图片的形式,传上来不好看,就自己描述吧. 第一题:单词分类 题目大意:有n个单词(n<=10000),如果两个单词中每个字母 ...

  3. Educational Codeforces Round 15 套题

    这套题最后一题不会,然后先放一下,最后一题应该是大数据结构题 A:求连续最长严格递增的的串,O(n)简单dp #include <cstdio> #include <cstdlib& ...

  4. Moscow Pre-Finals Workshop 2016. Japanese School OI Team Selection. 套题详细解题报告

    写在前面 谨以此篇题解致敬出题人! 真的期盼国内也能多出现一些这样质量的比赛啊.9道题中,没有一道凑数的题目,更没有码农题,任何一题拿出来都是为数不多的好题.可以说是这一年打过的题目质量最棒的五场比赛 ...

  5. Codeforces 437C The Child and Toy(贪心)

    题目连接:Codeforces 437C  The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> ...

  6. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

  7. 【51Nod】1510 最小化序列 贪心+动态规划

    [题目]1510 最小化序列 [题意]给定长度为n的数组A和数字k,要求重排列数组从而最小化: \[ans=\sum_{i=1}^{n-k}|A_i-A_{i+k}|\] 输出最小的ans,\(n \ ...

  8. 【套题】qbxt国庆刷题班D1

    Day1 事实上D1的题目还是比较简单的= =然而D1T2爆炸了就十分尴尬--错失一波键盘 看题 T1 传送门 Description 现在你手里有一个计算器,上面显示了一个数\(S\),这个计算器十 ...

  9. nyoj 16-矩形嵌套(贪心 + 动态规划DP)

    16-矩形嵌套 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:13 submit:28 题目描述: 有n个矩形,每个矩形可以用a,b来描述,表示长和 ...

随机推荐

  1. Activiti工作流——流程表数据转化

    任务流程部署:  启动流程实例: 请假人完成请假申请: 部门经理完成审批: 总经理审批完成:

  2. 【BZOJ】1601: [Usaco2008 Oct]灌水

    [算法]最小生成树 [题解] 想到网络流,但是好像不能处理流量和费用的关系. 想到最短路,但好像不能处理重复选边的问题. 每条边只需要选一次,每个点就要遍历到,可以想到最小生成树. 建超级源向每个点连 ...

  3. jQuery右侧悬浮楼层滚动 电梯菜单

    http://www.kaiu.net/effectCon.aspx?id=2198 <!doctype html> <html> <head> <meta ...

  4. 使用BackgroundWorker

    1,WPF应用程序为单线程模型(STAThread),所有UI控件都是主线程创建的,只有主线程能操作UI元素的显示. 2,其他工作线程要维护UI控件的显示,需调用主线程的Dispather,执行Inv ...

  5. Ubuntu安装pip

    首先打开终端 在终端输入:sudo apt-get install python-pip python-dev build-essential [+] 如果需要在Python3下安装pip,那么在py ...

  6. css position的值

    值 描述 absolute 生成绝对定位的元素,相对于 static 定位以外的第一个父元素进行定位. 元素的位置通过 "left", "top", " ...

  7. Vue组件-组件的注册

    注册组件 全局组件 注册组件就是利用Vue.component()方法,先传入一个自定义组件的名字,然后传入这个组件的配置. Vue.component('my-component', { templ ...

  8. chromedriver版本 支持的Chrome版本

    在使用selenium测试时,如果选择chrome浏览器,需要将chrome driver的exe文件放在项目下 错误的driver版本,会导致无法正常打开本机的浏览器 以下为对应关系 来自网络 ch ...

  9. [Leetcode Week15]Populating Next Right Pointers in Each Node II

    Populating Next Right Pointers in Each Node II 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/popul ...

  10. [Leetcode Week13]Search a 2D Matrix

    Search a 2D Matrix 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/search-a-2d-matrix/description/ D ...