BZOJ1930 [Shoi2003]pacman eats peas

Source: Internet
Author: User

DP, first built diagram, F[i][j] said a eat to I point, b eat to the maximum value of J point, transfer when the transfer topological sequence of the small, if I topological sequence is less than J, then transferred to F[k][j], otherwise transferred to F[i][k], the number of graphs to be built to optimize, otherwise it will time out. The optimization method is if the i,j is connected, then if there is an edge (i,k), x[k]>x[j] and Y[k]>y[j] then (I,K) This edge is not necessary to exist. It is better to fetch (I,J) in the j,k than to fetch (I,K) directly.

Code

1#include <cstdio>2#include <algorithm>3 #defineN 100104 using namespacestd;5 intN,i,j,rd[n],t,w,tot,id[n];6 intdp,pre[3000000],p[n],tt[3000000],z[n],id[n],tmp;7 intf[2500][2500];8 structg{9     intx, y;Ten }a[n]; One BOOLCMP (g A,g b) A { -     if(a.x==b.x) -     returna.y<b.y; the     returna.x<b.x; - } - voidLinkintXinty) - { +dp++;p re[dp]=p[x];p [x]=dp;tt[dp]=y; - } + voidDp (intXinty) A { at     inti; -I=P[x]; -      while(i) -     { -             inta=tt[i],b=y; -             if(id[a]>Id[b]) in Swap (A, b); -             if(a!=b) toF[a][b]=max (f[a][b],f[x][y]+1); +             Else -f[a][b]=Max (f[a][b],f[x][y]); theI=Pre[i]; *     } $ }Panax Notoginseng intMain () - { thescanf"%d",&n); +      A      for(i=1; i<=n;i++) thescanf"%d%d",&a[i].x,&a[i].y); +Sort (A +1, A +1+n,cmp); -      for(i=1; i<=n;i++) $     { $tmp=0x37373737*2; -      for(j=i+1; j<=n;j++) -     if(i!=j) && (a[i].x<=a[j].x) && (A[I].Y&LT;=A[J].Y) && (a[j].y<tmp)) the     { -tmp=a[j].y;Wuyird[j]++; the link (i,j); -     } Wu     } -      for(i=1; i<=n;i++) About     { $Link0, i); rd[i]++; -Link (i,n+1); rd[n+1]++; -     } -t=0; w=1; z[w]=0; A      while(t!=W) +     { thetot++; -t++; $id[z[t]]=tot; theid[tot]=Z[t]; theI=P[z[t]]; the          while(i) the         { -rd[tt[i]]--; in             if(rd[tt[i]]==0) the             { thew++;z[w]=Tt[i]; About             } theI=Pre[i]; the         } the     } +  -      the      for(i=1; i<=tot;i++)Bayi          for(j=i;j<=tot;j++) the Dp (Id[i],id[j]); theprintf"%d\n", f[n+1][n+1]-1); -}

BZOJ1930 [Shoi2003]pacman eats peas

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.