WUST OJ 1421 we love girl(貪心或DP)
Description
When taking part in ACM Programming Contest,many school hope girls for reception like ccnu,cug and so on.So this year our wust send more girls as possible to have a reception.The ratio of male to female of wust is seven to one,so we may not have so many girls.Of course the rest receptionist is boys.
Now there are n schools take part in Wust ACM Programming Contest,x girls and y boys is willing to help.If a school is received buy girls,they will get p satisfaction.If received buy boys ,they will get q satisfaction.We want to improve the total satisfaction of every school.Do you know the max satisfaction?
Input
The first line contains an integer T(T<=100), indicates the number of cases.For each test case,the first line contains three positive integers n (1<=n<=20),x and y (x>=0,y>=0,x+y>=n).n is the amount of schools and x is the amount of girls and y is the amount of boys.Then n lines follows, each line contains two integers pi and qi which means the two satisfaction of girls and boys.
Output
For each test case,print one integer which is the max satisfaction.
Sample Input
2
3 2 1
2 1
4 2
1 2
4 2 2
3 2
2 4
10 9
4 0
Sample Output
8
20
這個題當時貪心寫的。n比較小,發揮不了貪心優勢。
由於只有兩種選擇,選擇一種就意味著放棄另一種。
我們貪心的策略就是按照選男孩和女孩差值排序,然後每次
選最優的(如果可能)
#include
#include
#include
#include
#include
#include
#include
#include
#include