Xtreme9.0 - Car Spark 动态规划
Car Spark
题目连接:
https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/car-spark
Description
John is a computer programmer and is highly known for his achievements in his field. In addition to being a passionate software professional, he is also passionate about motorcars and motorbikes.
So, after ending his successful and lengthy software career, he decides to take up his passion. He starts an organization by the name "Car Spark" (CS). CS is an organization from which you can rent luxury cars of your choice on an hourly rental basis.
CS would like to accept bookings for the weekend in advance, and then decide which bookings to process based on the profits that would be earned. When placing an order, customers quote the amount that they are willing to pay for that vehicle during that particular timespan. Since a car can only be given to one customer during a particular time period, CS must be careful about which bookings to process.
Initially CS has only one vehicle available for rent. To be the first hire for CS, you must develop a program to maximize revenue on bookings for this vehicle.
Input
Input begins with a single integer T, 1 <= T <= 100, which denotes number of test cases.
Each test case begins with a single integer N, 1 <= N <= 2000, which is the number of bookings John received.
The remainder of the test case consists of N lines containing three integers Bs, Be, and Ai each separated by a space, where Bs is the booking start time, Be is the booking end time, and Ai is the amount that the customer is willing to spend for the entire booking. Note that 0 <= Bs < Be <= 48 and 1 <= Ai <= 100000.
Note: The car may only be rented during the weekend, meaning from 12:00 AM on Saturday to 12:00 AM on Monday. Since the two days in the weekend have 48 hours, 12 noon on a Sunday would be the (24+12) 36th hour. Similarly, if the booking start time is 10:00 PM on Saturday and the booking end time is 12:00 AM on Sunday, then Bs would be 22 and Be would be 24.
Output
You are to output a single line for each test case, giving the maximum revenue John can make from the orders he received.
Sample Input
2
4
1 2 100
2 3 200
3 4 1600
1 3 2100
3
1 10 2000
2 5 100
6 9 400
Sample Output
3700
2000
Hint
For the first test case, for the time slot 1-3 maximum revenue John can make is 2100 (Max(100+200, 2100)) and for slot 3-4 he can make 1600. The maximum total revenue is 3700 (2100+1600).
Similarly for second test case, the maximum revenue he can generate is 2000.
题意
给你n个区间,每个区间有权值,然后让你选择不相交的区间,使得权值和最大。
题解
按照右端点排序之后,然后跑dp
这道题数据范围很小,所以直接暴力跑就行了。
代码
#include<bits/stdc++.h>
using namespace std;
int dp[50];
struct node{
    int l,r;
    int val;
};
bool cmp(node a,node b)
{
    if(a.r==b.r)return a.l<b.l;
    return a.r<b.r;
}
node p[3005];
void solve()
{
    memset(dp,0,sizeof(dp));
    int n;scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d%d%d",&p[i].l,&p[i].r,&p[i].val);
    sort(p,p+n,cmp);
    for(int i=0;i<n;i++)
        for(int j=p[i].l;j>=0;j--)
            dp[p[i].r]=max(dp[p[i].r],dp[j]+p[i].val);
    int ans = 0;
    for(int i=0;i<50;i++)
        ans=max(ans,dp[i]);
    cout<<ans<<endl;
}
int main()
{
    int t;scanf("%d",&t);
    while(t--)solve();
    return 0;
}												
											Xtreme9.0 - Car Spark 动态规划的更多相关文章
- 基于Spark1.3.0的Spark sql三个核心部分
		
基于Spark1.3.0的Spark sql三个核心部分: 1.可以架子啊各种结构化数据源(JSON,Hive,and Parquet) 2.可以让你通过SQL,saprk内部程序或者外部攻击,通过标 ...
 - Xtreme9.0 - Communities 强连通
		
Xtreme9.0 - Communities 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/c ...
 - Xtreme9.0 - Light Gremlins 容斥
		
Xtreme9.0 - Light Gremlins 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenge ...
 - IEEEXtreme Practice Community  Xtreme9.0 - Digit Fun!
		
Xtreme9.0 - Digit Fun! 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/di ...
 - yarn 0.9.0 build spark
		
1. 下载scala并安装.版本为2.10.3.设置SCALA_HOME和PATH环境变量 2. 下载SPARK 0.9.0源代码并解压到/root/Downloads/spark-0.9.0-inc ...
 - Hadoop2.0/YARN深入浅出(Hadoop2.0、Spark、Storm和Tez)
		
随着云计算.大数据迅速发展,亟需用hadoop解决大数据量高并发访问的瓶颈.谷歌.淘宝.百度.京东等底层都应用hadoop.越来越多的企 业急需引入hadoop技术人才.由于掌握Hadoop技术的开发 ...
 - Spark 1.0.0 横空出世 Spark on Yarn 部署(Hadoop 2.4)
		
就在昨天,北京时间5月30日20点多.Spark 1.0.0最终公布了:Spark 1.0.0 released 依据官网描写叙述,Spark 1.0.0支持SQL编写:Spark SQL Progr ...
 - 初识Spark2.0之Spark SQL
		
内存计算平台spark在今年6月份的时候正式发布了spark2.0,相比上一版本的spark1.6版本,在内存优化,数据组织,流计算等方面都做出了较大的改变,同时更加注重基于DataFrame数据组织 ...
 - Installation of CarbonData 1.1.0 with Spark 1.6.2
		
关键词:carbondata spark thrift 数据仓库 [Install thrift 0.9.3] 注意 要装thrift-java必须先装ant . 有人说要装boost,我在cento ...
 
随机推荐
- UVALive 2218 Triathlon
			
https://vjudge.net/problem/UVALive-2218 题意: 铁人三项比赛,每项比赛长度未定,已知每个选手每项比赛的平均速度. 设计每项比赛的长度,让其中某个特定选手获胜. ...
 - Jquery教你写一个简单的轮播.
			
这个我表示写的不咋地-_-//,但是胜在简单,可优化性不错. 实际上我本来想写个复杂点的结构的,但是最近忙成狗了!!!!所以大家就讲究着看吧 HTML结构 <div class="ba ...
 - 史上最全的浏览器 CSS & JS Hack 手册
			
浏览器渲染页面的方式各不相同,甚至同一浏览器的不同版本(“杰出代表”是 IE)也有差异.因此,浏览器兼容成为前端开发人员的必备技能.如果有一份浏览器 Hack 手册,那查询起来就方便多了.这篇文章就向 ...
 - iOS 自己封装的网络请求,json解析的类
			
基本上所有的APP都会涉及网络这块,不管是用AFNetWorking还是自己写的http请求,整个网络框架的搭建很重要. 楼主封装的网络请求类,包括自己写的http请求和AFNetWorking的请求 ...
 - yui压缩JS和CSS文件
			
CSS和JS文件经常需要压缩,比如我们看到的XX.min.js是经过压缩的JS. 压缩文件第一个是可以减小文件大小,第二个是对于JS文件,默认会去掉所有的注释,而且会去掉所有的分号,也会将我们的一些参 ...
 - WEBAPI 帖子收藏
			
[翻译]ASP.NET Web API入门 [翻译]ASP.NET WEB API异常处理 ASP.NET WebAPI 路由规则与POST数据 ASP.NET Web API路由规则(二) ASP. ...
 - javascript对话框(弹出层)组件
			
http://www.blueidea.com/download/product/2010/7513.asp#comment 1. 从头到尾对一遍<<Javascript高级程序设计> ...
 - Android: 详解触摸事件如何传递
			
当视图的层次结构比较复杂的时候,触摸事件的响应流程也变得复杂. 举例来说,你也许有一天想要制作一个手势极其复杂的 Activity 来折磨你的用户,你经过简单思索,认为其中应该包含一个 PageVie ...
 - activiti主要组件解析
			
Activiti内部实现中,各主要部件关系 对外,提供Service服务,它是无状态的. 这些Service包括: protected RepositoryService repositoryServ ...
 - Laravel Model 的 fillable (白名单)与 guarded (黑名单)
			
例如 protected $fillable = ['name']; protected $guarded = ['price']; 定义了 name 字段可以写入/修改,而 price 字段不可以. ...