uva 11908 - Skyscraper (dp)
来源:互联网 发布:学格斗的软件 编辑:程序博客网 时间:2024/06/05 02:00
J
Skyscraper
The Build n' Profit construction company is about to build its tallest building. It will be huge, the tallest building in the world by a wide margin. It will house hundreds of thousands of people and have rocket-powered elevators to the upper floors. They even plan for a shuttle docking station instead of a helipad on its roof. But any building of that size is extremely costly to build and maintain, and even after selling and renting out all the floor-space it will be very difficult to meet the costs. Luckily, they have come up with a great solution. They will place advertisements on the outer walls of the building for a hefty charge. This will help offset some of the costs and bring in a profit.
However, feedbacks from prospective buyers of this advertisement space have brought up a new problem. Each customer wants a specific sized advertisement placed at a specific height, and they will pay a certain amount of money for it. Each advertisement order specifies its position (i.e. the lowest floor of the advertisement) and its size (i.e. the number of floors it covers, including the starting floor). Each advertisement spans the whole face of the building, so no two advertisements can occupy the same floor and no floors can be partially covered. Each order also includes the amount to be earned if that advertisement is placed on the building. Of course, no money is earned if only part of an advertisement is placed, or it is placed in any other position.
Since many of the advertisements want some of the same floors as others, it is often impossible to choose all of them. Can you help choosing which of the orders to accept so that the above constraints are fulfilled and the amount of profit is maximized?
Input
The first line of input will contain T (≤ 50) denoting the number of cases.
Each case starts with an integer N (1 ≤ N ≤ 30000) denoting the number of advertisement orders. Each of the next N lines represents an advertisement by three integers A (0 ≤ A ≤ 105), B (1 ≤ B ≤ 105) and C (1 ≤ C ≤ 1000) denoting the lowest floor, the number of floors the advertisement covers (including the lowest floor) and the amount of money earned for placing it, respectively.
Output
For each case, print the case number and the maximum profit they can achieve.
Sample Input
Output for Sample Input
1
3
1 5 1
2 10 3
7 12 1
Case 1: 3
Problem Setter: Muntasir Azam Khan, Special Thanks: Kazi Rakibul Hossain, Jane Alam Jan
这题比较简单,关键是要注意数组开到2*10^5,re好多次!
#include <cstdio>#include <algorithm>#include <vector>#include <map>#include <queue>#include <iostream>#include <stack>#include <set>#include <cstring>#include <stdlib.h>#include <cmath>using namespace std;typedef long long LL;typedef pair<int, int> P;const int maxn = 200000 + 5;const int INF = 1000000000;int dp[maxn];struct Node{ int x, y, c; Node(int x=0, int y=0, int c=0){ this -> x = x; this -> y = x+y-1; this -> c = c; }}p[maxn];bool cmp(Node a, Node b){ if(a.y == b.y) return a.c > b.c; return a.y < b.y;}int main(){ int t, kase = 0; scanf("%d", &t); while(t--){ kase++; int n; scanf("%d", &n); int Max = 0; for(int i = 0;i < n;i++){ int x, y, c; scanf("%d%d%d", &x, &y, &c); p[i] = Node(x, y, c); Max = max(Max, x+y-1); } sort(p, p+n, cmp); int pos = 0; memset(dp, 0, sizeof(dp)); if(p[0].y == 0){ dp[0] = p[0].c; } for(int i = 1;i <= Max && pos < n;){ dp[i] = max(dp[i-1], dp[i]); if(p[pos].y == i){ int last = p[pos].x-1; if(last >= 0) dp[i] = max(dp[i], dp[last]+p[pos].c); else{ dp[i] = max(dp[i], p[pos].c); } pos++; } else if(p[pos].y < i){ pos++; } else{ i++; } } printf("Case %d: %d\n", kase, dp[Max]); } return 0;}
- uva 11908 - Skyscraper (dp)
- UVA - 11908 Skyscraper
- uva 718 - Skyscraper Floors(模拟优化)
- Light OJ 1360 Skyscraper (线段树+DP)
- UVA 718 - Skyscraper Floors(数论)
- uva 718 - Skyscraper Floors(数论+bfs)
- bzoj2621[Usaco2012 Mar]Cows in a Skyscraper 状压dp
- HOJ 3282 skyscraper(拓扑排序)
- uva 10599(dp)
- uva 10118(DP)
- uva 10128 - Queue(dp)
- UVA 1424 - Salesmen(dp)
- uva 10149 - Yahtzee(DP)
- UVA 1371 - Period(DP)
- uva 12034 Race(dp)
- uva 10593 Kites(dp)
- uva 10128 Queue (dp)
- UVa 10559 Blocks(DP)
- 黑马程序员——Java—GUI编程
- C++课上ppt5复习 Polymorphism
- 前端工程师的修真秘籍(css、javascript和其它)
- 大数相加
- 装机-服务器重装server2008系统卡在了“你想将windows安装在何处”或“找不到驱动器”
- uva 11908 - Skyscraper (dp)
- 牛人啊
- mfc ado 帮助
- MVC3网站发布 c:\windows\system32\inetsrv> "C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\cs...
- SVM最全面的数学证明
- AndroidUI组件之GridView
- hdu 3613 Best Reward
- c++ 计算时间的date类
- 【Lucene最终总结】