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

内容概要:本文系统阐述了企业新闻发稿在生成式引擎优化(GEO)时代下的全渠道策略与效果评估体系,涵盖当前企业传播面临的预算、资源、内容与效果评估四大挑战,并深入分析2025年新闻发稿行业五大趋势,包括AI驱动的智能化转型、精准化传播、首发内容价值提升、内容资产化及数据可视化。文章重点解析央媒、地方官媒、综合门户和自媒体四类媒体资源的特性、传播优势与发稿策略,提出基于内容适配性、时间节奏、话题设计的策略制定方法,并构建涵盖品牌价值、销售转化与GEO优化的多维评估框架。此外,结合“传声港”工具实操指南,提供AI智能投放、效果监测、自媒体管理与舆情应对的全流程解决方案,并针对科技、消费、B2B、区域品牌四大行业推出定制化发稿方案。; 适合人群:企业市场/公关负责人、品牌传播管理者、数字营销从业者及中小企业决策者,具备一定媒体传播经验并希望提升发稿效率与ROI的专业人士。; 使用场景及目标:①制定科学的新闻发稿策略,实现从“流量思维”向“价值思维”转型;②构建央媒定调、门户扩散、自媒体互动的立体化传播矩阵;③利用AI工具实现精准投放与GEO优化,提升品牌在AI搜索中的权威性与可见性;④通过数据驱动评估体系量化品牌影响力与销售转化效果。; 阅读建议:建议结合文中提供的实操清单、案例分析与工具指南进行系统学习,重点关注媒体适配性策略与GEO评估指标,在实际发稿中分阶段试点“AI+全渠道”组合策略,并定期复盘优化,以实现品牌传播的长期复利效应。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值