当前位置:网站首页>Longest increasing subsequence
Longest increasing subsequence
2022-06-11 02:57:00 【ambition_ forever】
package LongestIncrSub;
import java.util.Arrays;
import java.util.HashSet;
/**
* Function description
* The longest increasing subsequence
*/
public class Main {
public static void getLongestIncrSub(int[] arr) {
int len = arr.length;
int[] dp = new int[len];
int[] res = new int[len];
Arrays.fill(dp, 1);
Arrays.fill(res, 0);
int maxNum = arr[0];
int maxDp = 0;
for (int i = 0; i < len; i++) {
maxNum = Math.max(maxNum, arr[i]);
for (int j = i; j >= 0; j--) {
if (arr[i] > arr[j]) {
dp[i] = 1 + dp[j];
res[i] = arr[j];
maxDp = Math.max(maxDp, dp[i]);
break;
}
}
}
HashSet<Integer> resSet = new HashSet<>();
for (int redI : res) {
if (redI == 0) {
continue;
边栏推荐
猜你喜欢

HUST Software Engineering (Experiment 2) -- TDD test driven development experiment.

Use of CIN and cout

Link list of high frequency written interview question brushing summary (distribution explanation & code annotation)

Write my Ini configuration file error

Blue Bridge Cup_ Xiao Lan eats candy_ Pigeon nest principle / drawer principle

完成千万元A轮融资,小象生活能否成为折扣界的“永辉”?

【斐波那契数列】

第七章 常用的协议简介(1)

靠贴牌飞利浦冲击上市,德尔玛的自有品牌又该如何“起跳”?

Arduino Uno接JQ8900-16p语音播报模块
随机推荐
A digit DP
Introduction to the functions of today's headline search webmaster platform (portal)
[interview question 17.04. missing numbers]
位置数据融合表3
Niuke: two numbers that only appear once in the array
What is ttfb
Forest v1.5.22 发布!支持Kotlin
CPT 102_LEC 13-14
How to fix syntax errors in WordPress websites
How to add cookie pop-up window in WordPress website (without plug-in)
微信小程序
Link list of high frequency written interview question brushing summary (distribution explanation & code annotation)
Uni app - one click access to user information
6 best WordPress Image optimizer plug-ins to improve WordPress website performance
[C language classic]: inverted string
Limiting visibility of symbols when linking shared libraries
GraphAcademy 課程講解:《Neo4j 圖數據科學基礎》
Tests logiciels vocabulaire commun anglais
OpenJudge NOI 1.13 18:Tomorrow never knows?
OpenJudge NOI 1.13 18:Tomorrow never knows?