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

13 篇文章 0 订阅
8 篇文章 0 订阅

链接:登录—专业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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值