ZOJ 3905 Cake ZOJ Monthly, October 2015 - C

本文探讨了一种蛋糕分配算法,通过动态规划解决Alice和Bob如何公平分配蛋糕的问题,旨在最大化Alice所得蛋糕价值总和。
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 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
1
6
1 6
7 10
6 11
12 18
15 5
2 14
Sample Output
28

Author: HUA, Yiwei

 

题意:给出n个二元组,若选取(ai, bi),就必须去掉一个(aj,bj),并且bj比bi大,问最终取得的ai的和最大为多少

分析:按照bi排序后,即便为,若选择第i个数,则必须去掉编号大于i的一项

倒着dp,dp[i][j]表示后i位取了j个的最大和,显然j<=(n-i+1)/2

简单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>
10 #include <vector>
11 #include <deque>
12 #include <queue>
13 using namespace std;
14 typedef long long LL;
15 typedef double DB;
16 #define Rep(i, n) for(int i = (0); i < (n); i++)
17 #define Repn(i, n) for(int i = (n)-1; i >= 0; i--)
18 #define For(i, s, t) for(int i = (s); i <= (t); i++)
19 #define Ford(i, t, s) for(int i = (t); i >= (s); i--)
20 #define rep(i, s, t) for(int i = (s); i < (t); i++)
21 #define repn(i, s, t) for(int i = (s)-1; i >= (t); i--)
22 #define MIT (2147483647)
23 #define MLL (1000000000000000000LL)
24 #define INF (1000000001)
25 #define mk make_pair
26 #define ft first
27 #define sd second
28 #define clr(x, y) (memset(x, y, sizeof(x)))
29 #define sqr(x) ((x)*(x))
30 #define sz(x) ((int) (x).size())
31 #define puf push_front
32 #define pub push_back
33 #define pof pop_front
34 #define pob pop_back
35 inline void SetIO(string Name) {
36     string Input = Name+".in", Output = Name+".out";
37     freopen(Input.c_str(), "r", stdin);
38     freopen(Output.c_str(), "w", stdout);
39 }
40 
41 const int N = 810;
42 typedef pair<int, int> II;
43 II Data[N];
44 int n, Arr[N], Dp[N][N];
45 
46 inline int Getint() {
47     int Ret = 0;
48     char Ch = ' ';
49     while(!(Ch >= '0' && Ch <= '9')) Ch = getchar();
50     while(Ch >= '0' && Ch <= '9') {
51         Ret = Ret*10+Ch-'0';
52         Ch = getchar();
53     }
54     return Ret;
55 }
56 
57 inline void Solve();
58 
59 inline void Input() {
60     int TestNumber;
61     //scanf("%d", &TestNumber);
62     TestNumber = Getint();
63     while(TestNumber--) {
64         n = Getint();
65         For(i, 1, n) {
66             Data[i].sd = Getint();
67             Data[i].ft = Getint();
68         }
69         Solve();
70     }
71 }
72 
73 inline void Solve() {
74     sort(Data+1, Data+1+n);
75     For(i, 1, n) Arr[i] = Data[i].sd;
76     
77     For(i, 1, n)
78         For(j, 1, n) Dp[i][j] = -INF;
79     Dp[n][0] = 0;
80     Ford(i, n-1, 1)
81         For(j, 0, (n-i+1)/2) {
82             Dp[i][j] = Dp[i+1][j];
83             if(j) Dp[i][j] = max(Dp[i][j], Dp[i+1][j-1]+Arr[i]);
84         }
85     
86     printf("%d\n", Dp[1][n/2]);
87 }
88 
89 int main() {
90      Input();
91      //Solve();
92     return 0;
93 }
View Code

 

转载于:https://www.cnblogs.com/StupidBoy/p/4883800.html

当前,全球经济格局深刻调整,数字化浪潮席卷各行各业,智能物流作为现代物流发展的必然趋势和关键支撑,正迎来前所未有的发展机遇。以人工智能、物联网、大数据、云计算、区块链等前沿信息技术的快速迭代与深度融合为驱动,智能物流不再是传统物流的简单技术叠加,而是正在经历一场从自动化向智能化、从被动响应向主动预测、从信息孤岛向全面互联的深刻变革。展望2025年,智能物流系统将不再局限于提升效率、降低成本的基本目标,而是要构建一个感知更全面、决策更精准、执行更高效、协同更顺畅的智慧运行体系。这要求我们必须超越传统思维定式,以系统化、前瞻性的视角,全面规划和实施智能物流系统的建设。本实施方案正是基于对行业发展趋势的深刻洞察和对未来需求的精准把握而制定。我们的核心目标在于:通过构建一个集成了先进感知技术、大数据分析引擎、智能决策算法和高效协同平台的综合智能物流系统,实现物流全链路的可视化、透明化和智能化管理。这不仅是技术层面的革新,更是管理模式和服务能力的全面提升。本方案旨在明确系统建设的战略方向、关键任务、技术路径和实施步骤,确保通过系统化部署,有效应对日益复杂的供应链环境,提升整体物流韧性,优化资源配置效率,降低运营成本,并最终为客户创造更卓越的价值体验。我们致力于通过本方案的实施,引领智能物流迈向更高水平,为构建现代化经济体系、推动高质量发展提供强有力的物流保障。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值