POJ 1065 Wooden Sticks

Source: Internet
Author: User

POJ 1065 Wooden Sticks

N Wood long l_i heavy w_i, the former wood is larger than the next one to waste a minute to prepare the machine, the most provincial solution?

We abstracted the question, that is: dividing a sequence into a minimum of the longest non-ascending subsequence

Dilworth theorem: For a partial order set, the minimum chain division equals the longest inverse chain length.

This problem is the minimum chain of two tuples, then we sort by a[] for the keyword size, if a[] in the same order according to B[], according to

Dilworth theorem, then the title becomes the longest strictly descending sub-sequence length in the b[] sequence.

1#include <iostream>2#include <algorithm>3#include <functional>4 using namespacestd;5  6pair<int,int> stick[ the+ -];7 intdp[ the+ -]; 8 intMain ()9 {Ten     intT; OneCIN >>T; A      while(t--) -     { -         intN; theCIN >>N; -          for(inti =0; I < n; ++i) -         { -CIN >> Stick[i].first >>Stick[i].second; +         } -Sort (stick, stick +n); +Memset (DP,-1Nsizeof(int)); A          for(intj =0; J < N; ++j) at         { -             //the longest descent sequence length method -*lower_bound (DP, DP + N, stick[j].second, greater<int> ()) =Stick[j].second; -         } -cout << Lower_bound (DP, DP + N,-1,greater<int> ())-DP <<Endl; -     } in     return 0; -}

POJ 1065 Wooden Sticks

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.