当前位置:网站首页>LeetCode 1626. The best team without contradiction
LeetCode 1626. The best team without contradiction
2022-07-07 16:59:00 【@Little safflower】
Problem description
Suppose you are the manager of the team . For the upcoming tournament , You want to form a team with the highest overall score . The score of a team is the score of all the players in the team The sum of the .
However , Contradictions in the team will limit the players' play , So you have to choose one There is no contradiction The team of . If a younger player's score Strictly greater than An older player , There are contradictions . There will be no contradiction between players of the same age .
Here are two lists scores and ages, Each group scores[i] and ages[i] It means the first one i Score and age of players . Please return The highest score of all possible non contradictory teams .
Example 1:
Input :scores = [1,3,5,10,15], ages = [1,2,3,4,5]
Output :34
explain : You can select all players .
Example 2:Input :scores = [4,5,6,5], ages = [2,1,2,1]
Output :16
explain : The best choice is after 3 player . Be careful , You can select multiple players of the same age .
Example 3:Input :scores = [1,2,3,5], ages = [8,9,10,1]
Output :6
explain : The best choice is before 3 player .
Tips :
1 <= scores.length, ages.length <= 1000
scores.length == ages.length
1 <= scores[i] <= 106
1 <= ages[i] <= 1000source : Power button (LeetCode)
link :https://leetcode.cn/problems/best-team-with-no-conflicts
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Java
class Solution {
public int bestTeamScore(int[] scores, int[] ages) {
int n = scores.length;
int[][] player = new int[n][2];// Age and score
for(int i = 0;i < n;i++){
player[i][0] = ages[i];
player[i][1] = scores[i];
}
// Sort
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++){
// Without conflict
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;
}
}边栏推荐
- A tour of gRPC:03 - proto序列化/反序列化
- 在哪个期货公司开期货户最安全?
- Inner monologue of accidental promotion
- Introduction to ThinkPHP URL routing
- Imitate the choice of enterprise wechat conference room
- skimage学习(1)
- 面向接口编程
- 作为Android开发程序员,android高级面试
- Skimage learning (3) -- gamma and log contrast adjustment, histogram equalization, coloring gray images
- Process from creation to encapsulation of custom controls in QT to toolbar (I): creation of custom controls
猜你喜欢

Cesium(3):ThirdParty/zip. js
直接上干货,100%好评

掌握这个提升路径,面试资料分享
最新Android高级面试题汇总,Android面试题及答案

Pycharm IDE下载

Advanced C language -- function pointer

Talk about the realization of authority control and transaction record function of SAP system

Master this set of refined Android advanced interview questions analysis, oppoandroid interview questions

AutoLISP series (2): function function 2

Temperature sensor chip used in temperature detector
随机推荐
logback. XML configure logs of different levels and set color output
The process of creating custom controls in QT to encapsulating them into toolbars (II): encapsulating custom controls into toolbars
Prediction - Grey Prediction
二叉搜索树(特性篇)
Direct dry goods, 100% praise
Lowcode: four ways to help transportation companies enhance supply chain management
URL和URI的关系
在哪个期货公司开期货户最安全?
LeetCode 1043. 分隔数组以得到最大和 每日一题
Cesium (4): the reason why gltf model is very dark after loading
QML初学
SqlServer2014+: 创建表的同时创建索引
JS中null NaN undefined这三个值有什么区别
Usage of config in laravel
Deep listening array deep listening watch
Personal notes of graphics (2)
Three. JS series (3): porting shaders in shadertoy
【DesignMode】外观模式 (facade patterns)
typescript ts 基础知识之类型声明
[designmode] facade patterns