OJ_3950_Cake
2016-03-22 18:33
281 查看
CakeTime Limit: 4 Seconds Memory Limit: 65536 KB提示:贪心思想+dpAlice 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 have 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, at 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 an integer T which is the number of test cases.For each test case, the first line is an integer n (1<=n<=800). Note thatn is always an even integer.In following n lines, each line contains two integers a[i] andb[i], where a[i] is the value of ith cake that Alice evaluates, andb[i] is the value of ith cake that Bob evaluates. (1<=a[i],b[i]<=1000000)Note that a[1], a[2]..., aare n distinct integers andb[1], b[2]..., bare n distinct integers.Output
For each test case, you need to output the maximum sum of the value that Alice can get in a line.Sample Input
1 6 1 6 7 10 6 11 12 18 15 5 2 14
Sample Output
28
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<set>#include<cmath>#include<stack>#include<map>using namespace std;const int N=805;int dp;struct node{int A,B;bool operator<(const node& X)const{return B>X.B;}}que;int main(){int t;int n;scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d%d",&que[i].A,&que[i].B);}memset(dp,0,sizeof(dp));sort(que+1,que+1+n);for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){dp[i][j]=dp[i-1][j];if(i/2>=j)dp[i][j]=max(dp[i][j],dp[i-1][j-1]+que[i].A);}}printf("%d\n",dp[n>>1]);}return 0;}
相关文章推荐
- 【bzoj3533】[Sdoi2014]向量集 三分+线段树+凸包
- 斜率优化(CDQ分治,Splay平衡树):BZOJ 1492: [NOI2007]货币兑换Cash
- UNIX网络编程:select,epoll,poll比较
- java.io.File源码探索
- javax.servlet.ServletException: java.lang.NoClassDefFoundError: count/Counter即找不到JavaBean文件
- NSOJ Constructing Roads(图论)
- IOS沙盒机制
- KMP 题解
- iBatis中关于count(*)的写法
- Oracle Study之-AIX6.1构建Oracle 10gR2 RAC(1)
- 基于正点原子战舰开发板的贪吃蛇游戏
- 5分钟弄懂Docker!
- Oracle 学习笔记 11 -- 视图 (VIEW)
- 实习笔试题,源代码编译
- java中queue的使用
- 树莓派日记之 GPIO
- 《练手_快排的实现》
- Less语言特性
- webservice SOAP WSDL UDDI
- Spark—聚合操作—combineByKey