HDU 1051(ZZULI 1609) Wooden St…
来源:互联网 发布:yii2.0框架源码下载 编辑:程序博客网 时间:2024/05/16 08:04
WoodenSticks
Time Limit:1000MS
Total Submit:33 Accepted:9
Description
There is a pile of nwooden sticks. The length and weight of each stick are known inadvance. The sticks are to be processed by a woodworking machine inone by one fashion. It needs some time, called setup time, for themachine to prepare processing a stick. The setup times areassociated with cleaning operations and changing tools and shapesin the machine. The setup times of the woodworking machine aregiven 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 , themachine will need no setup time for a stick of length l' and weightw' 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 nwooden sticks. For example, if you have five sticks whose pairs oflength and weight are ( 9 , 4 ) , ( 2 , 5 ) , ( 1 , 2 ) , ( 5 , 3 ), and ( 4 , 1 ) , then the minimum setup time should be 2 minutessince there is a sequence of pairs ( 4 , 1 ) , ( 5 , 3 ) , ( 9 , 4) , ( 1 , 2 ) , ( 2 , 5 ) .
Input
The input consists of Ttest cases. The number of test cases (T) is given in the first lineof the input file. Each test case consists of two lines: The firstline has an integer n , 1 <= n <=5000 , that represents the number of wooden sticks in the testcase, and the second line contains 2n positive integers l1 , w1 ,l2 , w2 ,..., ln , wn , each of magnitude at most 10000 , where liand wi are the length and weight of the i th wooden stick,respectively. The 2n integers are delimited by one or morespaces.
Output
The output should containthe minimum setup time in minutes, one per line.
SampleInput
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
SampleOutput
213
Source
这题纠结的我都不知道什么是贪心,什么是二分匹配了,好郁闷,为了研究这题我还和三多,老三,研究了一整个晚上,最后才弄明白,以后绝不要犯错……
贪心嘛,不解释
代码:
(这是三多的思想)
#include<stdlib.h>
structnode{
}stick[5008];
intcmp(const void *a,const void *b)
{
}
intmain()
{