ZOJ 3905 Ant ZOJ Monthly, October 2015-c

Source: Internet
Author: User

Cake Time limit: 4 Seconds Memory Limit: 65536 KB

Alice and Bob like eating cake very much. One day, Alice and Bob went to a bakery and bought many cakes.

Now we know that they has bought n cakes in the bakery. Both of them like delicious cakes, but they evaluate the cakes as different values. So they decided to divide those cakes by following method.

Alice and Bob do n /2 steps in each step, Alice choose 2 Cakes, and Bob takes the cake that he evaluates it greater, And Alice take the rest cake.

Now, Alice want to know the maximum sum of the value, that she can get.

Input

The first line is a integer which is the number of the T test cases.

For each test case, the first line was an integer n (1<= n <=800). Note that's always an n even integer.

In following n lines, each line contains-integers a[i] b[i] and, where is the a[i] value of ith cake that Ali Ce evaluates, and is the b[i] value of ith cake that Bob evaluates. (1<= a[i] , b[i] <=1000000)

Note that a[1] , a[2] ..., is a[n] n distinct integers and b[1] , b[2] ..., is b[n] n distinct integer S.

Output

For each test case, you need to the output of the maximum sum of the value of this Alice can get in a line.

Sample Input
161 67 106 1112 1815 52 14
Sample Output
28

Author: HUA, Yiwei

Test instructions: Given n two-tuple, if selected (AI, bi), you must remove one (AJ,BJ), and BJ is larger than Bi, ask the ultimate AI and the maximum number of

Analysis: After the order of BI, even if you select the number of I, you must remove a number greater than I

Inverted Dp,dp[i][j] indicates that the post I bit took J Max and, apparently j<= (n-i+1)/2

Simple DP

1#include <cstdio>2#include <cstring>3#include <cstdlib>4#include <cmath>5#include <ctime>6#include <iostream>7#include <algorithm>8#include <map>9#include <Set>Ten#include <vector> One#include <deque> A#include <queue> - using namespacestd; -typedefLong LongLL; thetypedefDoubleDB; - #defineRep (i, n) for (int i = (0); I < (n); i++) - #defineREPN (i, n) for (int i = (n)-1; I >= 0; i--) - #defineFor (I, S, T) for (int i = (s); I <= (t); i++) + #defineFord (I, T, s) for (int i = (t); I >= (s); i--) - #defineRep (I, S, T) for (int i = (s); I < (t); i++) + #defineREPN (I, S, T) for (int i = (s)-1; I >= (t); i--) A #defineMIT (2147483647) at #defineMLL (1000000000000000000LL) - #defineINF (1000000001) - #defineMk Make_pair - #defineFT first - #defineSD Second - #defineCLR (x, y) (memset (x, y, sizeof (x))) in #defineSQR (x) ((x) * (x)) - #defineSZ (x) ((int) (x). Size ()) to #definePUF Push_front + #definePub push_back - #definePOF Pop_front the #definePOB pop_back *InlinevoidSetio (stringName) { $     stringInput = name+". in", Output = name+". out";Panax NotoginsengFreopen (Input.c_str (),"R", stdin); -Freopen (Output.c_str (),"W", stdout); the } +  A Const intN =810; thetypedef pair<int,int>II; + II Data[n]; - intN, Arr[n], dp[n][n]; $  $InlineintGetint () { -     intRet =0; -     CharCh =' '; the      while(! (Ch >='0'&& Ch <='9')) Ch =GetChar (); -      while(Ch >='0'&& Ch <='9') {WuyiRet = ret*Ten+ch-'0'; theCh =GetChar (); -     } Wu     returnRet; - } About  $InlinevoidSolve (); -  -InlinevoidInput () { -     intTestnumber; A     //scanf ("%d", &testnumber); +Testnumber =Getint (); the      while(testnumber--) { -n =Getint (); $for (I,1, N) { theDATA[I].SD =Getint (); thedata[i].ft =Getint (); the         } the Solve (); -     } in } the  theInlinevoidSolve () { AboutSort (data+1, data+1+n); thefor (I,1, n) arr[i] =data[i].sd; the      thefor (I,1, N) +For (J,1, n) dp[i][j] =-INF; -dp[n][0] =0; theFord (i, N-1,1)BayiFor (J,0, (n-i+1)/2) { theDP[I][J] = dp[i+1][j]; the             if(j) Dp[i][j] = max (Dp[i][j], dp[i+1][j-1]+arr[i]); -         } -      theprintf"%d\n", dp[1][n/2]); the } the  the intMain () { - Input (); the      //Solve (); the     return 0; the}
View Code

ZOJ 3905 Ant ZOJ Monthly, October 2015-c

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.