HDOJ 3669 Cross the Wall

斜率优化DP。。。

按w递减,w相等h递增的顺序排序,扫一遍让w递减h递增

dp[now][i]=min( dp[pre][j]+W[j+1]*H[i])   k-1<=j<=i-1

维护一个下凸的曲线,斜率优化

Cross the Wall

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others)

Total Submission(s): 4340    Accepted Submission(s): 787

Problem Description

“Across the Great Wall, we can reach every corner in the world!” Now the citizens of Rectland want to cross the Great Wall.

The Great Wall is a huge wall with infinite width and height, so the only way to cross is to dig holes in it. All people in Rectland can be considered as rectangles with varying width and height, and they can only dig rectangle holes in the wall. A person can
pass through a hole, if and only if the person’s width and height is no more than the hole’s width and height both. To dig a hole with width W and height H, the people should pay W * H dollars. Please note that it is only permitted to dig at most K holes for
security consideration, and different holes cannot overlap each other in the Great Wall. Remember when they pass through the wall, they must have their feet landed on the ground.

Given all the persons’ width and height, you are requested to find out the minimum cost for digging holes to make all the persons pass through the wall.

Input

There are several test cases. The first line of each case contains two numbers, N (1 <= N <= 50000) and K (1 <= K <= 100), indicating the number of people and the maximum holes allowed to dig. Then N lines followed, each contains two integers wi and
hi (1 <= wi, hi <= 1000000), indicating the width and height of each person.

Output

Output one line for each test case, indicates the minimum cost.

Sample Input

2 1
1 100
100 1
2 2
1 100
100 1

Sample Output

10000
200

Source

2010 Asia Regional Harbin

时间: 2024-08-04 09:22:04

HDOJ 3669 Cross the Wall的相关文章

hdu 3669 Cross the Wall(斜率优化DP)

题目连接:hdu 3669 Cross the Wall 题意: 现在有一面无限大的墙,现在有n个人,每个人都能看成一个矩形,宽是w,高是h,现在这n个人要通过这面墙,现在只能让你挖k个洞,每个洞不能重叠,每个洞需要消耗你挖的w*h,现在问你最小消耗多少. 题解: 设dp[i][j]为前j个人挖i个洞的最小消耗. 首先我们先将每个人按w排序,我们可以发现,排序后的h是递减的,因为如果不是递减的,可以把那个点消掉,因为w[k]<w[j]&&h[k]<h[j]的话,那么第k个人就可

hdoj 2124 Repair the Wall 【贪心】

题意:有一栋墙坏了(台风吹坏的,并且宽度一定),这个猪脚要修这栋墙,并且找到了一些宽度跟刮坏的墙一样,只是长度不一样的木块,让你求这些木块能不能修好这堵墙, 一句话就是判断这些的木块的长度的和能不能大于破坏的墙的长度,如果能,输出最少用几块, 不能输出impossible. 这道题水的不行...从大到小排下序就好了 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2124 代码: #include<stdio.h> #include<algo

【HDOJ】1484 Basic wall maze

BFS. 1 /* 1484 */ 2 #include <iostream> 3 #include <queue> 4 #include <string> 5 #include <cstdio> 6 #include <cstring> 7 #include <algorithm> 8 using namespace std; 9 10 typedef struct { 11 int x, y; 12 string s; 13 }

hdu 3669(斜率优化DP)

Cross the Wall Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others)Total Submission(s): 4479    Accepted Submission(s): 812 Problem Description “Across the Great Wall, we can reach every corner in the world!” Now the

hdu3669之二维斜率DP

Cross the Wall Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others) Total Submission(s): 4176    Accepted Submission(s): 748 Problem Description "Across the Great Wall, we can reach every corner in the world!" No

【转】斜率优化DP和四边形不等式优化DP整理

当dp的状态转移方程dp[i]的状态i需要从前面(0~i-1)个状态找出最优子决策做转移时 我们常常需要双重循环 (一重循环跑状态 i,一重循环跑 i 的所有子状态)这样的时间复杂度是O(N^2)而 斜率优化或者四边形不等式优化后的DP 可以将时间复杂度缩减到O(N) O(N^2)可以优化到O(N) ,O(N^3)可以优化到O(N^2),依次类推 斜率优化DP和四边形不等式优化DP主要的原理就是利用斜率或者四边形不等式等数学方法 在所有要判断的子状态中迅速做出判断,所以这里的优化其实是省去了枚举

CAB202 Assignment 1

CAB202 Assignment 1, Semester 2 2019Assessment Weight: 30%ContextYou are tasked with bringing to life the classic characters of Tom and Jerry in a terminal basedgame. Tom is a cat with the simple agenda of catching the mouse, Jerry, running rampant i

HDOJ 1348 Wall 凸包

Wall Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4001    Accepted Submission(s): 1131 Problem Description Once upon a time there was a greedy King who ordered his chief Architect to build a

【HDOJ】1348 Wall

计算几何-凸包模板题目,Graham算法解. 1 /* 1348 */ 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 #include <cstdlib> 6 #include <cmath> 7 #include <algorithm> 8 using namespace std; 9 10 #define MAXN 1005 11 12 typed