我需要返回數組的LIS
。最長的子序列數
僞例如:
if the arr is
int []arr = {2,4,90,-3,-2,-1,-10,-9,-8};
num of LIS is: 3
2,4,90
-3,-2,-1
-10,-9,-8
例子2:
arr [] = {2,-3,4,90,-2,-1,-10,-9,-8};
num of LIS is: 4
2,4,90
-3,4,90
-3,-2,-1
-10,-9,-8
我試圖做到這一點:
int [] A = {2,4,90,-3,-2,-1,-10,-9,-8};
int[] dp = new int[A.length];
for (int i = 0; i < A.length; i++) {
dp[i] = 1;
for (int j = 0; j <= i - 1; j++) {
if (A[j] < A[i]) {
dp[i] = dp[i] + dp[j];
}
}
System.out.println(dp[dp.length - 1]) ;
}
你面臨什麼問題? – Kakarot
您應該嘗試找到最小值,然後將其分配 – Kakarot
'C'或'Java' ?? – devnull