ZOJ 3905 Cake
来源:互联网 发布:如何评价张国荣 知乎 编辑:程序博客网 时间:2024/05/21 14:53
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 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 that n is always an even integer.
In following n lines, each line contains two integers a[i] and b[i], where a[i] is the value of ith cake that Alice evaluates, and b[i] is the value of ith cake that Bob evaluates. (1<=a[i], b[i]<=1000000)
Note that a[1], a[2]..., a[n] are n distinct integers and b[1], b[2]..., b[n] are 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
161 67 106 1112 1815 52 14
Sample Output
28
先按b从大到小排序,然后像做背包一样搞就好了
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn=1005;int T,n,m,f[maxn][maxn];struct point{int a,b;void read(){scanf("%d%d",&a,&b);}bool operator<(const point&f) const{return b>f.b;}}u[maxn];int main(){scanf("%d",&T);while (T--){memset(f,0,sizeof(f));scanf("%d",&n);for (int i=1;i<=n;i++) u[i].read();sort(u+1,u+n+1);for (int i=1;i<=n;i++){f[i][0]=0;for (int j=1;j+j<=i;j++){f[i][j]=max(f[i-1][j],f[i-1][j-1]+u[i].a);}}printf("%d\n",f[n][n/2]);}return 0;}
- ZOJ 3905 Cake (DP)
- zoj 3905 Cake
- ZOJ 3905 Cake
- ZOJ 3905 Cake(dp)
- ZOJ 3905 Cake(dp)
- zoj 3905 Cake(状压dp)
- ZOJ-3905-Cake【贪心】【dp】
- Cake ZOJ
- Cake ZOJ
- zoj 3511 Cake Robbery
- zoj 3511 Cake Robbery
- zoj 3511 Cake Robbery
- ZOJ-3537 Cake
- ZOJ - 3537 —— Cake
- ZOJ 3537 Cake (区间DP6)
- zoj 3407 Doraemon's Cake Machine
- zoj 1460 The Partition of a Cake
- ZOJ Monthly, July 2011 【B 】Cake Robbery
- 【月报】Android开发实习的第一个月——为什么进度这么慢
- 51nod 活动安排问题之二 (贪心+stl)
- C#实现控制摄像头的类
- NEU1579(斜率优化)
- 线程的创建和启动
- ZOJ 3905 Cake
- 3d游戏的总体设计框架
- C# 三种序列化方法分享
- 博客小技巧:程序演示效果GIF图录制
- 深入浅出 JavaWeb:Servlet必会必知
- C#实现对Json字符串处理
- java 文件上传与下载
- HTML/CSS/Js/Jquery/PHP网站0基础开发到大神系列【飞鸽学院】
- ZOJ 3911Prime Query