当前位置:网站首页>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;
}
}
边栏推荐
- Usage of config in laravel
- [summary of knowledge] summary of notes on using SVN in PHP
- 打造All-in-One应用开发平台,轻流树立无代码行业标杆
- pycharm 终端部启用虚拟环境
- Master this set of refined Android advanced interview questions analysis, oppoandroid interview questions
- 无法将“pip”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
- Cesium (4): the reason why gltf model is very dark after loading
- 最新Android面试合集,android视频提取音频
- Sqlserver2014+: create indexes while creating tables
- Vs2019 configuration matrix library eigen
猜你喜欢
整理几个重要的Android知识,高级Android开发面试题
字节跳动Android金三银四解析,android面试题app
Three. JS series (1): API structure diagram-1
AutoLISP series (3): function function 3
Spark Tuning (III): persistence reduces secondary queries
预售17.9万,恒驰5能不能火?产品力在线,就看怎么卖
Horizontal and vertical centering method and compatibility
水平垂直居中 方法 和兼容
time标准库
预测——灰色预测
随机推荐
HAVE FUN | “飞船计划”活动最新进展
Spark Tuning (III): persistence reduces secondary queries
Laravel 服务提供者实例教程 —— 创建 Service Provider 测试实例
作为Android开发程序员,android高级面试
最新Android高级面试题汇总,Android面试题及答案
记一次项目的迁移过程
Arduino 控制的双足机器人
The difference and working principle between compiler and interpreter
【MySql进阶】索引详解(一):索引数据页结构
字节跳动Android面试,知识点总结+面试题解析
射线与OBB相交检测
如何选择合适的自动化测试工具?
OpenGL personal notes
Pisa-Proxy SQL 解析之 Lex & Yacc
Ray and OBB intersection detection
LeetCode-SQL第一天
平衡二叉树(AVL)
【Vulnhub靶场】THALES:1
os、sys、random标准库主要功能
模拟Servlet的本质