当前位置:网站首页>牛客多校4 A.Task Computing 思维
牛客多校4 A.Task Computing 思维
2022-08-01 22:16:00 【Strezia】
题意
n ( n ≤ 1 e 5 ) n(n\leq 1e5) n(n≤1e5) 个物品,每个物品有 w i , p i w_i, p_i wi,pi ,现从中取出 m ( m ≤ 20 ) m(m\leq 20) m(m≤20) 件,最大化
思路
这种题一般都是通过比较交换相邻两项后对答案的贡献,得出一种排序方法,排序之后计算即可。
假设现在选了 k k k 件物品,这个式子其实就是 S u m = w 1 + w 2 ∗ ( p 1 ) + w 3 ∗ ( p 1 p 2 ) + . . . + w k ∗ ( p 1 p 2 . . . p k − 1 ) Sum = w_1 + w_2*(p_1) + w_3*(p_1p_2)+...+w_k*(p_1p_2...p_{k-1}) Sum=w1+w2∗(p1)+w3∗(p1p2)+...+wk∗(p1p2...pk−1) 。考虑如果再选一件 ( w 0 , p 0 ) (w_0,p_0) (w0,p0) 放在最前面,则 S u m = w 0 + p o ∗ S u m Sum = w_0+p_o*Sum Sum=w0+po∗Sum 。推导如图。之后排序即可。
代码
struct Node {
double w, p;
bool operator < (const Node &x) const {
return w * (1 - x.p) > x.w * (1 - p);
}
}node[maxn];
int n, m;
double f[maxn][25]; //i-n中选j个最大值
void solve() {
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> node[i].w;
}
for(int i = 1; i <= n; i++) {
cin >> node[i].p;
node[i].p /= 10000;
}
sort(node + 1, node + n + 1);
for(int i = 1; i <= n; i++) {
for(int j = 0; j <= m; j++) f[i][j] = -INF;
}
f[n + 1][0] = 0;
for(int i = n; i >= 1; i--) {
for(int j = 0; j <= m; j++) {
f[i][j] = f[i+1][j];
if(j)
f[i][j] = max(f[i+1][j], f[i+1][j-1] * node[i].p + node[i].w);
}
}
cout << f[1][m] << endl;
}
边栏推荐
- Advanced Algebra_Proof_The algebraic multiplicity of any eigenvalue of a matrix is greater than or equal to its geometric multiplicity
- SAP Spartacus NgExpressEngineDecorator 的工作原理
- PHP算法之电话号码的字母组合
- Dichotomy Medium LeetCode6133. Maximum Number of Groups
- 小程序容器+自定义插件,可实现混合App快速开发
- 如何给 UE4 场景添加游戏角色
- 毕业十年,财富自由:那些比拼命努力更重要的事,从来没人会教你
- 统计单词数
- kubernetes CoreDNS全解析
- Yizhou Financial Analysis | The intelligent transformation of bank ATM machines is accelerated; the new Internet loan regulations bring challenges
猜你喜欢
10 Practical Uses of NFTs (NFT System Development)
SOM网络2: 代码的实现
【C语言实现】最大公约数的3种求法
[ASM] Bytecode Operation MethodWriter
感觉自己好傻
xctf attack and defense world web master advanced area webshell
LeetCode952三部曲之一:解题思路和初级解法(137ms,超39%)
10年稳定性保障经验总结,故障复盘要回答哪三大关键问题?|TakinTalks大咖分享
Small application project works WeChat stadium booking applet graduation design of the finished product (1) the development profile
Today's sleep quality record 74 points
随机推荐
罗克韦尔AB PLC RSLogix5000中的比较指令使用方法介绍
企业公众号文章写作方向:如何写出读者认可的优质内容
PAM 回文自动机
SAP Spartacus NgExpressEngineDecorator 的工作原理
ARFoundation Getting Started Tutorial U2-AR Scene Screenshot Screenshot
今日睡眠质量记录74分
【Verilog刷题篇】硬件工程师从0到入门1|基础语法入门
The must-have "fishing artifact" for programmers is here!
SOM网络2: 代码的实现
深度学习Course2第一周Practical aspects of Deep Learning习题整理
SOM网络1:原理讲解
2022 edition of MySQL tutorial, top collection good, take your time
dvwa 通关记录1 - 暴力破解 Brute Force
Go 微服务开发框架DMicro的设计思路
NgRx Store createSelector 的单步调试和源代码分析
Flutter基础学习(一)Dart语言入门
User Experience | How to Measure User Experience?
小程序毕设作品之微信美食菜谱小程序毕业设计成品(6)开题答辩PPT
No more rolls!After joining ByteDance for a week, he ran decisively.
10年稳定性保障经验总结,故障复盘要回答哪三大关键问题?|TakinTalks大咖分享