Wooden sticks
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 9125 accepted submission (s): 3729
Problem descriptionthere is a pile of N wooden sticks. the length and weight of each stick are known in advance. the sticks are to be processed by a woodworking machine in one by one fashion. it needs some time, called setup time, for the machine
Prepare processing a stick. The setup times are associated with cleaning operations and changing tools and shapes in the machine. The setup times of the woodworking machine are given as follows:
(A) The setup time for the first wooden stick is 1 minute.
(B) Right after processing a stick of length L and weight W, the machine will need no setup time for a stick of length l' and weight W' if l <= l' and W <= W '. otherwise, it will need 1 minute for setup.
You are to find the minimum setup time to process a given pile of N wooden sticks. for example, if you have five sticks whose pairs of length and weight are (), and ), then the minimum setup time shocould be 2 minutes since there is
A sequence of pairs ).
Inputthe input consists of T test cases. the number of test cases (t) is given in the first line of the input file. each test case consists of two lines: the first line has an integer N, 1 <= n <= 5000, that represents the number of wooden
Sticks in the test case, and the second line contains N 2 positive integers L1, W1, L2, W2 ,..., ln, Wn, each of magnloud at most 10000, where Li and WI are the length and weight of the I th wooden stick, respectively. the 2n integers are delimited by one
Or more spaces.
Outputthe output shoshould contain the minimum setup time in minutes, one per line.
Sample Input
3 5 4 9 5 2 2 1 3 5 1 4 3 2 2 1 1 2 2 3 1 3 2 2 3 1
Sample output
213
Sourceasia 2001, Taejon (South Korea)
# Include <stdio. h ># include <algorithm> using namespace STD; struct node // store stick attributes, long, heavy, whether to access {int L; int W; int V ;} STR [5002]; bool CMP (node A, Node B) // sort by length and weight from small to large {if (. L = B. l) return. W <B. w; return. L <B. l ;}int main () {int t, n; int Tim; int I, j; scanf ("% d", & T); While (t --) {Tim = 0; scanf ("% d", & N); for (I = 0; I <n; I ++) {scanf ("% d ", & STR [I]. l, & STR [I]. w); STR [I]. V = 0;} Sort (STR, STR + N, CMP); // sort int L, W; for (I = 0; I <n; I ++) // select the I-th wooden stick (after sorting) as the first wooden stick during processing {If (STR [I]. V = 0) {L = STR [I]. l; W = STR [I]. w; STR [I]. V = 1; Tim ++;} For (j = I + 1; j <n; j ++) {If (STR [J]. V = 0 & STR [J]. l> = L & STR [J]. w> = W) {L = STR [J]. l; W = STR [J]. w; STR [J]. V = 1 ;}} printf ("% d \ n", Tim) ;}return 0 ;}