BZOJ4426 : [Nwerc2015]Better Productivity最大生产率

如果一个区间包含另一个区间,那么这两个区间是否在一起的生产率是一样的。

将所有这种包含了其他区间的区间放入数组$b$,其余的放入数组$c$,有多个相同的时候则从$b$移一个到$c$。

那么$c$里所有区间左端点递增,右端点也递增,设$f[i][j]$为$c$中前$j$个区间划分成$i$组的最大收益,直接DP即可,决策具有单调性。

然后把$p$分配给$b$和$c$,求出$b$和$c$组合取来的最大收益即可。

时间复杂度$O(n^2\log n)$。

#include<cstdio>
#include<algorithm>
#define N 210
using namespace std;
int n,m,i,j,flag,cb,cc,s[N],f[N][N],ans=-2147400000;
struct P{int x,y;}a[N],b[N],c[N];
bool cmpb(P a,P b){return a.y-a.x>b.y-b.x;}
bool cmpc(P a,P b){return a.x<b.x;}
void dp(int p,int l,int r,int dl,int dr){
  int m=(l+r)>>1,dm=dl,t=ans;
  for(int i=min(m-1,dr);i>=dl;i--){
    if(c[i+1].y<=c[m].x)break;
    int now=f[p-1][i]+c[i+1].y-c[m].x;
    if(now>=t)t=now,dm=i;
  }
  f[p][m]=t;
  if(l<m)dp(p,l,m-1,dl,dm);
  if(r>m)dp(p,m+1,r,dm,dr);
}
int main(){
  scanf("%d%d",&n,&m);
  for(i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y);
  for(i=1;i<=n;i++){
    for(flag=0,j=1;j<=n;j++)if(a[i].x<=a[j].x&&a[j].y<=a[i].y&&(a[i].x!=a[j].x||a[i].y!=a[j].y||i<j)){flag=1;break;}
    if(flag)b[++cb]=a[i];else c[++cc]=a[i];
  }
  sort(b+1,b+cb+1,cmpb);
  for(i=1;i<=cb;i++)s[i]=s[i-1]+b[i].y-b[i].x;
  sort(c+1,c+cc+1,cmpc);
  for(i=1;i<=cc;i++)f[0][i]=ans;
  for(i=1;i<=m;i++)f[i][0]=ans;
  for(i=1;i<=m;i++)dp(i,1,cc,0,cc);
  for(i=1;i<=m;i++)if(m-i<=cb&&f[i][cc]>=0)ans=max(ans,f[i][cc]+s[m-i]);
  return printf("%d",ans),0;
}

  

时间: 2024-10-14 12:39:14

BZOJ4426 : [Nwerc2015]Better Productivity最大生产率的相关文章

DBMS的优点和缺点

1.6  Advantages and Disadvantages of DBMSs (数据库的优点和缺点) The database management system has promising potential advantages. (数据库管理系统具有广阔的潜在优势.) promising /pr'?misi?/ adj. someone or something that is promising seems likely to be very good or successful

免费的精品: Productivity Power Tools 动画演示

原文:免费的精品: Productivity Power Tools 动画演示 Productivity Power Tools 是微软官方推出的 Visual Studio 扩展,被用以提高开发人员生产率.它的出现一定程度上弥补和完善了 Visual Studio 自身的不足,比如其中的标记自动补全.复制引用等看似虽小,但却真得帮助我减轻了很多麻烦.博客园中推荐该扩展的文章也不在少数,本篇多少也有点类似,只是为了大家阅读方便,我为个别比较好有的功能配上了 GIF 动画. 该扩展中很多有用的功能

Productivity Power Tools 是微软官方推出的 Visual Studio 扩展

免费的精品: Productivity Power Tools 动画演示

bzoj 4430: [Nwerc2015]Guessing Camels赌骆驼

4430: [Nwerc2015]Guessing Camels赌骆 Description Jaap, Jan, and Thijs are on a trip to the desert after having attended the ACM ICPC World Finals 2015 in Morocco. The trip included a camel ride, and after returning from the ride, their guide invited th

A Productivity Hack in Four Quadrants

http://www.slideshare.net/paulgordonbrown/a-productivity-hack-in-four-quadrants A Productivity Hack in Four Quadrants 1. A Productivity in Four Hack Quadrants 2.The Eisenhower Productivity Matrix 3.Important NOT Important Your tasks are either import

VS 插件 Productivity Power Tools - 更改 选项卡组件位置

Visual Studio 2013怎么把选项卡设置在左侧显示?vs中选项卡默认显示在顶部,但是更习惯显示在左侧,该怎么设置呢?为了更方便使用,下面分享VS2013选项卡设置在左侧显示的图文教程 Visual Studio选项卡在顶部显示时,文件稍多的时候在选项卡之间切换时就稍显麻烦.为了使用Visual Studio开发式更顺手,把选项卡移动到左边显示一列会更方便一些. 1.打开Visual Studio 2013,选择菜单“工具”——“扩展和更新(U)” 2.在弹出的窗口左侧选择“联机”,然

Visual Studio Productivity Power Tools居然也开源

(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:微软开源玩得嗨,连VS扩展插件Productivity Power Tools也开源. Productivity Power Tools是微软开发的一个用于增强Visual Studio生产力的扩展插件,最初发布于2010年(应用于Visual Studio 2010).你甚至可以认为Productivity Power Tools是微软针对Visual Studio新功能的实验室,因为201

8 Productivity hacks for Data Scientists &amp; Business Analysts

8 Productivity hacks for Data Scientists & Business Analysts Introduction I was catching up with one of my friends from a past organization. She had always been interested in data science, but was only able to break into it about 10 months ago. She h

Productivity tips, tricks and hacks for academics (2015 edition)

Productivity tips, tricks and hacks for academics (2015 edition) Contents Jump to: My philosophy: Optimize transaction costs. Don't work from home. Eliminate temptation to waste time. Salvage dead time with technology. Get rid of your TV. Taming emai