当前位置:网站首页>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;
}
}边栏推荐
- 3000 words speak through HTTP cache
- 使用JSON.stringify()去实现深拷贝,要小心哦,可能有巨坑
- Arduino 控制的双足机器人
- Three. JS series (2): API structure diagram-2
- [designmode] flyweight pattern
- The latest interview experience of Android manufacturers in 2022, Android view+handler+binder
- 应用在温度检测仪中的温度传感芯片
- typescript ts基础知识之tsconfig.json配置选项
- 第九届 蓝桥杯 决赛 交换次数
- C语言进阶——函数指针
猜你喜欢

Vs2019 configuration matrix library eigen
![[medical segmentation] attention Unet](/img/f4/cf5b8fe543a19a5554897a09b26e68.png)
[medical segmentation] attention Unet

DNS 系列(一):为什么更新了 DNS 记录不生效?

预售17.9万,恒驰5能不能火?产品力在线,就看怎么卖
![[designmode] facade patterns](/img/79/cde2c18e2ec8b08697662ac352ff90.png)
[designmode] facade patterns

Spark Tuning (III): persistence reduces secondary queries

C语言进阶——函数指针

如何选择合适的自动化测试工具?

Advanced C language -- function pointer

Introduction and use of gateway
随机推荐
skimage学习(1)
OpenGL personal notes
Pycharm IDE下载
Direct dry goods, 100% praise
【Seaborn】组合图表、多子图的实现
[Android -- data storage] use SQLite to store data
URL和URI的关系
Advanced C language -- function pointer
Talk about the realization of authority control and transaction record function of SAP system
The difference and working principle between compiler and interpreter
skimage学习(3)——使灰度滤镜适应 RGB 图像、免疫组化染色分离颜色、过滤区域最大值
数据中台落地实施之法
[designmode] facade patterns
【PHP】PHP接口继承及接口多继承原理与实现方法
JS中null NaN undefined这三个值有什么区别
【Seaborn】组合图表:PairPlot和JointPlot
LeetCode 1477. 找两个和为目标值且不重叠的子数组 每日一题
Tidb cannot start after modifying the configuration file
LeetCode 1031. 两个非重叠子数组的最大和 每日一题
ORACLE进阶(六)ORACLE expdp/impdp详解