Hdu-6249 2017ccpc-final G.alice ' s stamps dynamic planning

Source: Internet
Author: User

Surface

Test instructions: give you N a collection, each set has L to r these kinds of stamps, let you choose the K collection, so that the last choice of the type of stamps as much as possible, n,l,r are <=2000

Puzzle: Easy to think about the network flow, but then think about it will find that can't handle this model

Then look at the data range, think of DP, define state F[I][J] represents the most species of J for the first I set,

We find that this needs to be n^3, because each time we enumerate i,j, we also enumerate a Q to record which of the new collections is extended from the last set.

Can't think of its solution, see the whole field is a, finally in the last 1h changed state (playing is of course the replay)

We found that L,r is only 2000 ah, just that definition if feasible, l,r not discrete, there is no need to say this

So define F[I][J], representing the kind of 1-i, with the best scheme of J-sets, for each position I, we first preprocess the up array, covering I, the interval of the most right to extend to where

Transfer is F[i][j+1]=max (F[i-1][j+1]f,[i][j+1]) if (Up[i]) F[up[i]][j+1]=max (f[up[i]][j+1],f[i-1][j]+len); Len is equal to up[i]-i+1;

1#include <bits/stdc++.h>2 #defineN 20053 using namespacestd;4 intf[n][n],up[n],t,t=1, n,m,k;5 intMain ()6 {7Cin>>T;8      while(t--)9     {Tenscanf"%d%d%d",&n,&m,&k); Onememset (UP,0,sizeofUp ); AMemset (F,0,sizeoff); -          for(intI=1, x,y;i<=m;i++) -         { thescanf"%d%d",&x,&y); -              for(intj=x;j<=y;j++) up[j]=Max (up[j],y); -         } -          for(intI=1; i<=n;i++) +              for(intj=0; j<k;j++) -             { +f[i][j+1]=max (f[i][j+1],f[i-1][j+1]); A                 if(Up[i]) f[up[i]][j+1]=max (f[up[i]][j+1],f[i-1][j]+up[i]-i+1); at             } -printf"Case #%d:%d\n", t++, F[n][k]); -     } -     return 0; -}

Hdu-6249 2017ccpc-final G.alice ' s stamps dynamic planning

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.