博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Xtreme9.0 - Car Spark 动态规划
阅读量:6822 次
发布时间:2019-06-26

本文共 2813 字,大约阅读时间需要 9 分钟。

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
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
=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<
<

转载地址:http://lhozl.baihongyu.com/

你可能感兴趣的文章
Open-Falcon 互联网企业级监控系统解决方案(2)
查看>>
抄录一份linux哲学思想
查看>>
cesiumjs开发实践(五) 坐标变换
查看>>
计算数据库中各个表的数据量和每行记录所占用空间的脚本-转载来自(博客园 桦仔)...
查看>>
解决本机不能访问虚拟机web服务器网站的问题
查看>>
Proxmox VE 安装、配置、使用之第一章 安装配置
查看>>
java经典算法(猴子吃桃)
查看>>
《linux Shell 脚本攻略》进阶学习(第二部分)
查看>>
mysql常用命令
查看>>
Leetcode PHP题解--D76 993. Cousins in Binary Tree
查看>>
http、https 等 常用默认端口号
查看>>
SQL SERVER的安装
查看>>
裸心社pinyin&IK settings
查看>>
Spring-Boot-操作-Redis,三种方案全解析!
查看>>
ubuntu 15.10下apache+php+mysql安装
查看>>
RHCE 学习笔记(28) Target Service
查看>>
2016年4月6日作业
查看>>
RxJava 学习笔记<十> 译 Leaving the monad
查看>>
Mariadb galera cluster 安装配置
查看>>
川模型 一款新的测试模型的提出与研究
查看>>