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 w i and h i (1 <= w i, h i <= 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
 


#include 
   
   
    
    
#include 
    
    
     
     
#include 
     
     
      
      
#include 
      
      
       
       

using namespace std;

typedef long long int LL;

const int maxn=50050;
const LL INF=1LL<<60;

struct Wall
{
    LL L,W;
    bool operator < (const Wall &B) const
    {
        if(L!=B.L) return L>B.L;
        return W
       
       
         N) K=N; int pre=0,now=1; LL ans=INF; for(int i=1;i<=N;i++) dp[pre][i]=INF; for(int k=1;k<=K;k++) { head=0;tail=0; q[tail++]=k-1; for(int i=k;i<=N;i++) { while(head+1 
        
          =x2*y1) tail--; else break; } q[tail++]=i; } ans=min(ans,dp[now][N]); swap(now,pre); } printf("%I64d\n",ans); } return 0; } 
         
       
      
      
     
     
    
    
   
   



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值