NOI2011 Noi Carnival

Source: Internet
Author: User

http://www.lydsy.com/JudgeOnline/problem.php?id=2436

First discretization, the time range after discretization is [1,cnt].

H[I][J], indicates how many times the time range is in [I,j], and can be resolved within n^2 time.

Assume that the site is a and B, respectively.

It is easy to know that the activities of venue A and site B must be:

The arrangement of their activities must have been so spaced out.

We beg F[i][j], indicating that when the time <=i, a site has a J activity, b venue, the maximum number of activities.

We do not know that the last activity is in the site A or B, but it must be the maximum value of the 2 cases, that is to say: F[i][j] "When the time <=i, a site has J activities and the last activity in a site, b site The maximum number of activities" and when the time <=i, A site has a J activity and the last activity on the B site, b site up to how many activities "the maximum value of both cases."

From small to large enumeration I.

First to reverse the loop J, with F[i][j+1] update F[i][j]:f[i][j]=max (f[i][j],f[i][j+1]).

We enumerate J, push backwards, enumerate K,

We can move to F[k][j]:f[k][j]=max (f[k][j],f[i][j]+h[i+1][k) if the next [i+1,k] time zone is the B site in action.

We can move to F[k][j+h[i+1][k]]:f[k][j+h[i+1][k]]=max (F[k][j+h[i+1][k]],f[i][j]) if the next [i+1,k] time interval is a site activity.

This can be solved in n^3 time.

Similarly, we beg G[i][j], said when the time >=i, a site has J activities, B site up to how many activities, is also n^3 time to resolve.

We then ask T[I][J] to indicate that all activities in [i,j] are at the site A, the maximum number of activities of the carnival with relatively little activity.

A very straightforward idea is:

$T [I][j]=max\{min (X+y+h[i][j],f[i-1][x]+g[j+1][y]) \} (0\leqslant x\leqslant n,0\leqslant y\leqslant N) $

But it must have been n^4.

We find that when x gets bigger, f[i-1][x] becomes smaller:

$min (X↑+y+h[i][j],f[i-1][x]↓+g[j+1][y]) $

If y also becomes larger, G[j+1][y] becomes smaller:

$min (x↑+y↑+h[i][j],f[i-1][x]↓+g[j+1][y]↓) $

As we take the min, there is no egg to use.

So y can only get smaller, g[j+1][y] and then grow bigger:

$min (x↑+y↓+h[i][j],f[i-1][x]↓+g[j+1][y]↑) $

So with the increment of x, y decrements.

And easy to know, this must be a single-peak.

So can n^3 find out ans[i][j].

The output of line 1th is $max\{min (I,f[cnt][i]) \} (0\leqslant i\leqslant N) $

The first i+1 output is $max (T[i][j]) (1\leqslant i\leqslant l,r\leqslant j\leqslant CNT) $

#include <cstdio>#include<cstdlib>#include<iostream>#include<fstream>#include<algorithm>#include<cstring>#include<string>#include<cmath>#include<queue>#include<stack>#include<map>#include<utility>#include<Set>#include<bitset>#include<vector>#include<functional>#include<deque>#include<cctype>#include<climits>#include<complex>//#include <bits/stdc++.h> for Cf,uoj, but not for POJ using namespaceStd;typedefLong LongLl;typedefDoubleDb;typedef pair<int,int>Pii;typedef Complex<DB>CP;#defineMmSt (a,v) memset (A,v,sizeof (a))#defineMmcy (A, B) memcpy (A,b,sizeof (a))#defineRe (I,A,B) for (i=a;i<=b;i++)#defineRed (i,a,b) for (i=a;i>=b;i--)#defineFi first#defineSe Second#defineM_p (A, B) Make_pair (A, B)#defineSF scanf#definePF printf#defineBoth (k) (1<< (k))Template<classT>inline T Sqr (t x) {returnx*x;} Template<classT>inlinevoidUpmin (T &t,t tmp) {if(t>tmp) t=tmp;} Template<classT>inlinevoidUpmax (T &t,t tmp) {if(t<tmp) t=tmp;}ConstDB eps=1e-9; inlineintSGN (DB x) {if(ABS (x) <eps)return 0;return(x>0)?1:-1;}ConstDB Pi=acos (-1.0); inlineintGint () {intres=0;BOOLneg=0;CharZ;  for(Z=getchar (); z!=eof && z!='-'&&!isdigit (z); z=GetChar ()); if(z==eof)return 0; if(z=='-') {neg=1; z=GetChar ();}  for(; z!=eof && isdigit (z); res=res*Ten+z-'0', z=GetChar ()); return(neg)?-Res:res; }inline ll Gll () {ll res=0;BOOLneg=0;CharZ;  for(Z=getchar (); z!=eof && z!='-'&&!isdigit (z); z=GetChar ()); if(z==eof)return 0; if(z=='-') {neg=1; z=GetChar ();}  for(; z!=eof && isdigit (z); res=res*Ten+z-'0', z=GetChar ()); return(neg)?-Res:res; }Const intmaxn= $;Const intMaxcnt=2*MAXN;intN;structtdata{intL,r,id;} a[maxn+Ten];intcnt,bak[2*maxn+ -];intt[maxcnt+Ten];inth[maxcnt+Ten][maxcnt+Ten];inlineBOOLCMPR (tdata X,tdata y) {returnx.r<Y.R;}intf[maxcnt+Ten][maxn+Ten],g[maxcnt+Ten][maxn+Ten];intt[maxcnt+Ten][maxcnt+Ten];intans,res[maxn+Ten];intMain () {/*freopen ("show.in", "R", stdin); Freopen ("Show.out", "w", stdout);*/      inti,j,k; N=Gint (); Re (i,1, N) A[i].l=gint (), A[i].r=a[i].l+gint ()-1, a[i].id=i; Re (i,1, N) bak[++cnt]=a[i].l,bak[++cnt]=A[I].R; Sort (Bak+1, bak+cnt+1); CNT=unique (bak+1, bak+cnt+1)-bak-1; Re (i,1, N) A[i].l=lower_bound (bak+1, bak+cnt+1, A[I].L)-bak,a[i].r=lower_bound (bak+1, bak+cnt+1, A[I].R)-Bak; Sort (a+1, a+n+1, CMPR); intHead=1; Re (i,1, CNT) {             while(head<=n && a[head].r<=i) t[a[head].l]++,head++; intsum=0; Red (J,i,1) sum+=t[j],h[j][i]=sum; } mmst (F,-1); f[0][0]=0; Re (i,0, cnt-1) {Red (J,n-1,0) Upmax (f[i][j],f[i][j+1]); Re (J,0, N) {                if(f[i][j]!=-1) Re (k,i+1, CNT) Upmax (f[k][j],f[i][j]+h[i+1][k]); if(f[i][j]!=-1) Re (k,i+1, CNT) Upmax (f[k][j+h[i+1][k]],f[i][j]); }} mmst (G,-1); G[cnt+1][0]=0; Red (i,cnt+1,2) {Red (J,n-1,0) Upmax (g[i][j],g[i][j+1]); Re (J,0, N) {                if(g[i][j]!=-1) Re (k,1, I-1) Upmax (g[k][j],g[i][j]+h[k][i-1]); if(g[i][j]!=-1) Re (k,1, I-1) Upmax (g[k][j+h[k][i-1]],g[i][j]); }} ans=0; Re (J,0, N) Upmax (Ans,min (j,f[cnt][j)); cout<<ans<<Endl; Re (i,1, CNT) Re (j,i,cnt) {T[i][j]=0; /*int x, y; Re (x,0,n) Re (y,0,n) if (f[i-1][x]!=-1 && g[j+1][y]!=-1) Upmax (T[i][j],min (x+y+h[i][j],f[ I-1][x]+g[j+1][y]));*/            intx,y=N;  while(Y1>=0&& g[j+1][y]==-1) y--; Re (x,0, N) {                  if(f[i-1][x]==-1)Continue;  while(Y1>=0&& min (x+y+h[i][j],f[i-1][x]+g[j+1][y]) <=min (x+y-1+h[i][j],f[i-1][x]+g[j+1][y-1])) y--; Upmax (t[i][j],min (x+y+h[i][j],f[i-1][x]+g[j+1][y])); }} re (I,1, N) {            intL=a[i].l,r=a[i].r,id=a[i].id; Res[id]=0; Re (J,1, L) Re (k,r,cnt) Upmax (Res[id],t[j][k]); } Re (I,1, N) cout<<res[i]<<Endl; return 0; }
View Code

NOI2011 Noi Carnival

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.