BZOJ4426: [Nwerc2015]better productivity Maximum productivity

Source: Internet
Author: User

If a range contains another interval, then the productivity of the two intervals is the same.

Put all the other intervals into the array $b$, the rest into the array $c$, there are more than one time from $b$ to $c$.

Then $c$ all the interval of the left endpoint increment, the right endpoint is also incremented, set $f[i][j]$ for the $c$ in the first $j$ interval divided into $i$ group of the maximum benefit, direct DP can, decision-making has monotonicity.

Then the $p$ assigned to $b$ and $c$, to find out the $b$ and $c$ combination of the maximum benefit can be obtained.

Time Complexity $o (n^2\log N) $.

#include <cstdio> #include <algorithm> #define N 210using 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&LT;M) DP (P,L,M-1,DL,DM); if (R&GT;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;}

  

BZOJ4426: [Nwerc2015]better productivity Maximum productivity

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.