链接:登录—专业IT笔试面试备考平台_牛客网
来源:牛客网

题目描述

See Problem N for PDF statements.

As it says, Time is Money, Efficiency is Life. A client has a computing task waiting for uploading to the cloud servers. However, due to the resource limits and many other tasks, a task usually cannot be worked on a single server but multiple servers, one after another. You, as an employee of a cloud server provider who specializes in task allocation, need to select several servers from a limited number of cloud servers to perform calculations. We know that even the same servers will perform differently in different environments.

There are nnn cloud servers available in the vicinity of the client's region numbered from 111 to nnn. The iii-th cloud server has two parameters: wiw_iwi​ and pip_ipi​, which indicate the computing power and transmission efficiency of that server, respectively. The supervisor requires that each task must be computed by exactly mmm of these servers. The client's computational task is not parallelizable, so you must sequence the work of the mmm servers to maximize the total computational efficiency. We define the total computational efficiency as follows:

∑i=1mwai∏j=0i−1paj\sum\limits_{i=1}^{m}w_{a_i}\prod\limits_{j=0}^{i-1}p_{a_j}i=1∑m​wai​​j=0∏i−1​paj​​

where a1,a2,…,ama_1,a_2,\ldots, a_ma1​,a2​,…,am​ (pairwise distinct, 1≤ai≤n1\le a_i \le n1≤ai​≤n) are the servers you selected. For convenience, a0=0,p0=1a_0 = 0, p_0 = 1a0​=0,p0​=1.

输入描述:

The first line contains two integers n,mn,mn,m (1≤n≤1051\le n\le 10^51≤n≤105, 1≤m≤min⁡(n,20)1\le m \le \min(n,20)1≤m≤min(n,20)), denoting the number of cloud servers and servers that you have to select.The second line contains nnn integers w1,w2,…,wnw_1,w_2,\ldots, w_nw1​,w2​,…,wn​ (1≤wi≤1091\le w_i \le 10^91≤wi​≤109), denoting the servers' computing power.The third line contains nnn integers q1,q2,…,qnq_1,q_2,\ldots, q_nq1​,q2​,…,qn​ (8000≤qi≤120008000\le q_i \le 120008000≤qi​≤12000), where pi=qi10000p_i = \frac{q_i}{10000}pi​=10000qi​​ denotes the iii-th server's transmission efficiency.

输出描述:

Output a float number denoting the maximal total computational efficiency. Your answer is considered correct if the relative or absolute error between yours and the standard solution is not greater than 10−610^{-6}10−6.

示例1

输入

复制5 2 1 2 3 4 5 12000 11000 10000 9000 8000

5 2
1 2 3 4 5
12000 11000 10000 9000 8000

输出

复制8.5000000000000000

8.5000000000000000

题意翻译

一个客户有一个计算任务等待上传云端。
一个任务不能只工作在一个服务器上,而是多个服务器。
你作为一个云服务器提供者专业于任务分配,
需要从数量有限的服务器中选出几个来进行计算。
我们知道,即便是相同的服务器在不同的环境中也会有
不同的表现。

有n个服务器在客户地的旁边可供选择,
编号是从1到n.
第i个服务器有两个参数:
wi和pi,
分别代表着那个服务器的计算能力和传输效率

提供者需要每个任务都必须被这些服务器中的m个进行计算。
客户端的计算任务是不可并行的,
所以你必须对m个服务器进行排序,以致最大的计算效率。

我们定义总的计算效率如下:
......

1.首先熟练一下累加累乘符号

2.如何排序,使得对答案的贡献值最大。 

#include <bits/stdc++.h>
#define double long double
using namespace std;
const int N=1e5+10;
int n,m;
double dp[N][21];
struct Node
{double w;double q;
}a[N];bool cmp(Node a,Node b)
{return (a.w+b.w*a.q)<(b.w+a.w*b.q);
}int main()
{cin>>n>>m;for(int i=1;i<=n;i++){scanf("%llf",&a[i].w);}for(int i=1;i<=n;i++){scanf("%llf",&a[i].q);a[i].q/=10000.0;}sort(a+1,a+1+n,cmp);double res=0.0;//有点背包那味儿~for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){dp[i][j]=dp[i-1][j];//if(j>=1)dp[i][j]=max(dp[i][j],dp[i-1][j-1]*a[i].q+a[i].w);}res=max(res,dp[i][m]);}printf("%.10llf\n",res);return 0;
}

牛客暑假四 A Task Computing 【如何排序使得对答案的贡献值最大】【cmp里面不等式的推导】【累加累乘符号的学习】【DP】相关推荐

  1. 牛客题霸 单链表的选择排序 C++题解/答案

    牛客题霸 单链表的选择排序 C++题解/答案 题目描述 给定一个无序单链表,实现单链表的选择排序(按升序排序). 题解: 不可能手写排序,这辈子不可能手写排序.. 基础的链表操作,将链表内的数据存到v ...

  2. 2021牛客暑假多校第八场 K题—Yet Another Problem About Pi

    2021牛客暑假多校第八场 K题-Yet Another Problem About Pi 题意:告诉你一个单元格的长和宽,问你走Π(3.1415926-)的长度距离最多可以走几个单元格 思路:沿着单 ...

  3. 2021牛客暑假多校第二场 K题—Stack (链表)

    2021牛客暑假多校第二场 K题-Stack 题意: 一个单调栈,给你第n次操作时里面数据的数量,让你给出里面塞入的会是哪些数字. 主要思想:链表模拟 (代码里面有注释) (题解一开始说的是拓扑,后来 ...

  4. 【2020年牛客暑假第八场】E题 Enigmatic Partition

    [2020年牛客暑假第八场]E题 Enigmatic Partition 一阶差分+隔项差分 题意 思路 方法一 方法二 Code 反思 题目链接: https://ac.nowcoder.com/a ...

  5. 【2020年牛客暑假第九场】E题 Groundhog Chasing Death

    [2020年牛客暑假第九场]E题 Groundhog Chasing Death 质因子分解 题意 思路 方法一:先枚举iii再枚举公共质因子 Code(286ms) 方法二:先枚举公共质因子再枚举i ...

  6. 牛客题霸 [将字符串转化为整数] C++题解/答案

    牛客题霸 [将字符串转化为整数] C++题解/答案 题目描述 实现函数 atoi .函数的功能为将字符串转化为整数 提示:仔细思考所有可能的输入情况.这个问题没有给出输入的限制,你需要自己考虑所有可能 ...

  7. 牛客题霸 [ 环形链表的约瑟夫问题] C++题解/答案

    牛客题霸 [ 环形链表的约瑟夫问题] C++题解/答案 题目描述 据说著名犹太历史学家 Josephus 有过以下故事:在罗马人占领乔塔帕特后,39 个犹太人与 Josephus 及他的朋友躲到一个洞 ...

  8. 牛客题霸 [输出二叉树的右视图] C++题解/答案

    牛客题霸 [输出二叉树的右视图] C++题解/答案 题目描述 请根据二叉树的前序遍历,中序遍历恢复二叉树,并打印出二叉树的右视图 题解: 分两个过程: 先用前序遍历+中序遍历恢复二叉树,这个应该都会. ...

  9. 牛客题霸 [链表中环的入口节点] C++题解/答案

    牛客题霸 [链表中环的入口节点] C++题解/答案 题目描述 对于一个给定的链表,返回环的入口节点,如果没有环,返回null 拓展: 你能给出不利用额外空间的解法么? 题解: 判断环有个很巧妙的方法, ...

最新文章

  1. python 求直线交点坐标
  2. MyBatis小问题(1)-Mapper中错误No constructor found...
  3. php过滤第一个逗号和最后一个逗号,PHP字符过滤函数去除字符串最后一个逗号(rtrim)...
  4. c语言文件归并问题_C语言 | 选择法对10个数排序
  5. 左神算法:加强堆的实现(Java)
  6. java实现输出下一秒_编写一个函数,要求输入年月日时分秒,输出该年月日时分秒的下一...
  7. (100)详细描述一个你做过的项目, 面试必问(二十四)(第20天)
  8. 矩阵sum_Matlab-sum与cumsum函数
  9. 韩国拟监管加密相关国际汇款,以限制资金流向海外
  10. [SGU223]Little Kings(状压DP)
  11. jetson tx2上运行mobilenet-ssd的坑:interrupted by signal 9: SIGKILL
  12. 【Mac版】小i译读安装操作
  13. 语法长难句之从句——名词性从句
  14. 基于AR眼镜有哪类功能可实现?
  15. redis如何查看主从状态信息master和salve
  16. 鸿蒙 OS 2.0 公测!已适配多款机型
  17. Linux:网络五元组tcp、udp特性
  18. 数据结构与算法10:图与图搜索
  19. CSR867x — 如何修改BLE的蓝牙地址
  20. Bugku Misc 我永远喜欢穹妹

热门文章

  1. 做好企业上网行为管理作用大-真实开发案例
  2. 使用ansible剧本源码包安装nginx
  3. Javadoc到底是什么??
  4. 百度,给SEO个冷屁股好吗?
  5. IDEA集成JProfiler
  6. 华为最便宜5G手机 华为畅享Z
  7. 智能视频识别技术的发展现状
  8. 树莓派系统dnsmasq服务器搭建
  9. 计算机室内设计 cad 论文,CAD室内设计毕业答辩论文.doc
  10. 【附源码】计算机毕业设计SSM校园考研互助网站