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