网站制作能在家做吗,做网站美工收费,自己做网站需不需要钱,wordpress 影楼主题文章目录1. 题目2. 解题1. 题目
https://tianchi.aliyun.com/oj/231188302809557697/235445278655844967
Twitter正在测试一种名为Pigeon的新工作处理服务。
Pigeon可以用任务实际持续时间的两倍处理任务#xff0c;并且每个任务都有一个权重。 此外#xff0c;Pigeon在一…
文章目录1. 题目2. 解题1. 题目
https://tianchi.aliyun.com/oj/231188302809557697/235445278655844967
Twitter正在测试一种名为Pigeon的新工作处理服务。
Pigeon可以用任务实际持续时间的两倍处理任务并且每个任务都有一个权重。 此外Pigeon在一个小时内只能服务一个有限的持续时间最大运行时间。
给定Pigon服务的最大运行时间任务的实际运行时间和权重确定Pigon服务在一小时内可以实现的最大总权重。
输入包括以下参数
n : 任务数量
weights : 每个任务的权重
tasks : 每个任务实际持续时间
p : Pigeon一小时的最大运行时间示例
样例1
输入:
4
[2,4,4,5]
[2,2,3,4]
15
输出: 10
说明:你可以运行0、1、2号任务
将花费2 * (2 2 3) 14 分钟并获得 2 4 4 10 权重。样例2
输入:
3
[3,2,2]
[3,2,2]
9
输出: 4
说明:你可以运行1、2号任务
将花费2 * (2 2) 8 分钟并获得 2 2 4 权重。2. 解题
class Solution {
public:/*** param n: the number of tasks* param weights: the weight for every task* param tasks: the actual duration of every task* param p: maximum runtime for Pigeon in an hour* return: the maximum total weight that the Pigeon service can achieve in an hour*/int maxWeight(int n, vectorint weights, vectorint tasks, int p) {// write your code herevectorvectorint dp(n, vectorint(p1, -1));// dp[i][j] 表示处理完 i 任务花费时间为 j 时 的最大权重和dp[0][0] 0;if(tasks[0]*2 p)dp[0][tasks[0]*2] weights[0];for(int i 1; i n; i){dp[i] dp[i-1];//复制上一次的状态当前的任务不做for(int t1 0; t1 p; t1){if(dp[i-1][t1] ! -1 t12*tasks[i] p){ //当前任务做dp[i][t12*tasks[i]] max(dp[i][t12*tasks[i]], dp[i-1][t1]weights[i]);}}}return *max_element(dp[n-1].begin(), dp[n-1].end());}
};53ms C
第4题https://tianchi.aliyun.com/oj/231188302809557697/235445278655844964 解题LeetCode 834. 树中距离之和树上DP* 我的CSDN博客地址 https://michael.blog.csdn.net/
长按或扫码关注我的公众号Michael阿明一起加油、一起学习进步