当前位置:网站首页>LeetCode 1626. 无矛盾的最佳球队 每日一题
LeetCode 1626. 无矛盾的最佳球队 每日一题
2022-07-07 15:32:00 【@小红花】
问题描述
假设你是球队的经理。对于即将到来的锦标赛,你想组合一支总体得分最高的球队。球队的得分是球队中所有球员的分数 总和 。
然而,球队中的矛盾会限制球员的发挥,所以必须选出一支 没有矛盾 的球队。如果一名年龄较小球员的分数 严格大于 一名年龄较大的球员,则存在矛盾。同龄球员之间不会发生矛盾。
给你两个列表 scores 和 ages,其中每组 scores[i] 和 ages[i] 表示第 i 名球员的分数和年龄。请你返回 所有可能的无矛盾球队中得分最高那支的分数 。
示例 1:
输入:scores = [1,3,5,10,15], ages = [1,2,3,4,5]
输出:34
解释:你可以选中所有球员。
示例 2:输入:scores = [4,5,6,5], ages = [2,1,2,1]
输出:16
解释:最佳的选择是后 3 名球员。注意,你可以选中多个同龄球员。
示例 3:输入:scores = [1,2,3,5], ages = [8,9,10,1]
输出:6
解释:最佳的选择是前 3 名球员。
提示:
1 <= scores.length, ages.length <= 1000
scores.length == ages.length
1 <= scores[i] <= 106
1 <= ages[i] <= 1000来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/best-team-with-no-conflicts
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
Java
class Solution {
public int bestTeamScore(int[] scores, int[] ages) {
int n = scores.length;
int[][] player = new int[n][2];//年龄和分数
for(int i = 0;i < n;i++){
player[i][0] = ages[i];
player[i][1] = scores[i];
}
//排序
Arrays.sort(player,(a,b) -> a[0] == b[0] ? a[1] - b[1] : a[0] - b[0]);
int[] dp = new int[n];
dp[0] = player[0][1];
int ans = dp[0];
for(int i = 1;i < n;i++){
dp[i] = player[i][1];
for(int j = 0;j < i;j++){
//不冲突的情况下
if(!(player[i][0] > player[j][0] && player[i][1] < player[j][1])){
dp[i] = Math.max(dp[i],dp[j] + player[i][1]);
}
}
ans = Math.max(ans,dp[i]);
}
return ans;
}
}
边栏推荐
- [summary of knowledge] summary of notes on using SVN in PHP
- 谈谈 SAP 系统的权限管控和事务记录功能的实现
- Laravel 服务提供者实例教程 —— 创建 Service Provider 测试实例
- 预售17.9万,恒驰5能不能火?产品力在线,就看怎么卖
- ORACLE进阶(六)ORACLE expdp/impdp详解
- Tragedy caused by deleting the console statement
- 一文读懂数仓中的pg_stat
- Talk about the realization of authority control and transaction record function of SAP system
- Interface oriented programming
- 最新2022年Android大厂面试经验,安卓View+Handler+Binder
猜你喜欢
随机推荐
JS 模块化
ATM system
SqlServer2014+: 创建表的同时创建索引
Three. JS series (3): porting shaders in shadertoy
Personal notes of graphics (4)
Build an all in one application development platform, light flow, and establish a code free industry benchmark
射线与OBB相交检测
logback. XML configure logs of different levels and set color output
ATM系统
typescript ts 基础知识之类型声明
Lie cow count (spring daily question 53)
PHP中exit,exit(0),exit(1),exit(‘0’),exit(‘1’),die,return的区别
Module VI
值得一看,面试考点与面试技巧
LocalStorage和SessionStorage
Set the route and optimize the URL in thinkphp3.2.3
模块六
Inner monologue of accidental promotion
全网“追杀”钟薛高
Laravel 服务提供者实例教程 —— 创建 Service Provider 测试实例