Poj 1609 tilining up Blocks

Source: Internet
Author: User

 

Tiling up Blocks
Time limit:1000 ms   Memory limit:10000 K
Total submissions:3016   Accepted:1148

Description

Michael the kid provided es an interesting game set from his grandparent as his birthday gift. Inside the game set box, there are n tiling blocks and each block has a form as follows:

Each tiling block is associated with two parameters (l, m), meaning that the upper face of the block is packed with L protruding knobs on the left and M protruding knobs on the middle. correspondingly, the bottom face of an (l, m)-block is carved with L caving dens on the left and M dens on the middle.
It is easily seen that an (l, m)-block can be tiled upon another (l, m)-block. however, this is not the only way for us to tile up the blocks. actually, an (l, m)-block can be tiled upon another (L', M')-block if and only if l> = l' and M> = M '.
Now the puzzle that Michael wants to solve is to decide what is the tallest tiling blocks he can make out of the given n blocks within his game box. in other words, you are given a collection of N Blocks B = {b1, b2 ,..., BN} and each block Bi is associated with two parameters (Li, mi ). the objective of the problem is to decide the number of tallest tiling blocks made from B.

Input

Several sets of tiling blocks. the inputs are just a list of integers. for each set of tiling blocks, the first integer n represents the number of blocks within the game box. following N, there will be n lines specifying parameters of blocks in B; each line contains exactly two integers, representing left and middle parameters of the I-th block, namely, Li and MI. in other words, a game box is just a collection of N Blocks B = {b1, b2 ,..., BN} and each block Bi is associated with two parameters (Li, mi ).
Note that N can be as large as 10000 and Li and MI are in the range from 1 to 100.
An integer n = 0 (zero) signifies the end of input.

Output

For each set of tiling Blocks B, output the number of the tallest tiling blocks can be made out of B. Output a single star '*' to signify the end
Outputs.

Sample Input

33 21 12 354 22 43 31 15 50

Sample output

23*

Source

Asia Kaohsiung 2003

 

 

/* <Br/> This is mainly used to find the largest ascending subsequence, but since the data size is n = 10000, therefore, <br/> If the General DP time complexity is n ^ 2, it is easy to start from time-out. Therefore, we come up with the binary DP, time <br/> the complexity is nlgn <br/> the binary DP query mainly requires two Arrays: <br/> one is the longest ascending subsequence that can be formed by the longgest [I] record ending with element I <br/> the other is the length of the smallest [l] [2] record l the minimum possible value of the Maximum ascending subsequence ending value <br/> sort the input data first, then, each element is processed at a time. When element I is processed, You Need To <br/> use the binary method to query the proper position where I can be inserted, assume that the query of I finally falls on the K position <br/> 1) if k <I, you need to determine whether I can update smallest [l] <br/> because input [I] and input [k] have two sizes, input [I] is not necessarily smaller than input [K], because the entire order Column <br/> has been sorted by L, so l does not need to be compared. All we need to do is to make the right value smaller than input [I]. R and smallest [k] [1], <br/> If the former is smaller than the latter, update <br/> In addition, you need to update longest [I] = K; <br/> 2) If K = I, it indicates that data I is the largest data currently. <br/> therefore, set longest [I] = I, smallest [I] = input [I] <br/> */<br/> # include <iostream> <br/> # include <algorithm> <br/> # define max_n 10000 <br/> using namespace STD; <br/> struct input <br/> {<br/> int L, R; <br/>} inputs [max_n + 1]; <br/> bool compare (const Input & I1, const input & I2) <br/>{< br/> If (i1.l <i2.l) return true; <br/> else if (i1.l = i2.l) <br/>{< br/> If (i1.r <= i2.r) return true; <br/> else return false; <br/>}< br/> else return false; <br/>}< br/> int longgest [max_n + 1]; // lonngest [I] records the longest ascending subsequence that can be formed at the end of element I <br/> int smallest [max_n + 1] [2]; // smallest [l] the minimum possible value of the end value of the longest ascending subsequence whose record length is L <br/> int N; <br/> int main () <br/>{< br/> int I, maxlen; <Br/> while (scanf ("% d", & N) & n! = 0) <br/>{< br/> maxlen = int_min; <br/> for (I = 1; I <= N; I ++) <br/> scanf ("% d", & inputs [I]. l, & inputs [I]. r); <br/> sort (& inputs [1], & inputs [1] + N, compare); <br/> int curlen = 0, left, right, lval, rval, mid; <br/> for (I = 1; I <= N; I ++) <br/> {<br/> lval = inputs [I]. l; rval = inputs [I]. r; <br/> left = 1; Right = curlen; <br/> while (left <= right) <br/>{< br/> mid = (left + right)/2; <br/> If (smallest [Mid] [1] <= rval) <br/> left ++; <br/> else right --; <br/>}< br/> longgest [I] = left; <br/> If (curlen = 0 | (lval <= smallest [left] [0] & rval <smallest [left] [1]) <br/> smallest [left] [0] = lval; smallest [left] [1] = rval; <br/> If (left> curlen) curlen = left; <br/> If (longgest [I]> maxlen) maxlen = longgest [I]; <br/>}< br/> printf ("% d/N ", maxlen); <br/>}< br/> printf ("*/N"); <br/> return 0; <br/>} 

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.