我是动态编程的新手,我尝试解决代码中的问题(A Kefa和第一步),它是代码强制http://codeforces.com/contest/580/problem/A中问题的链接 这是我的解决方案我不知道我的代码中有什么错误可以帮助我吗?
package problemsolvingg;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
public class mege {
public static int[] arr;
public static int[][] dp;
public static int n;
public static void clr(int n) {
for(int i = 0 ; i < n ; i++) {
for(int j = 0 ; j<n;j++) {
dp[i][j] = -1;
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
n = sc.nextInt(); arr = new int[n]; dp = new int[n][n];
clr(n);
for(int i = 0 ; i < n ; i++) {
arr[i] = sc.nextInt();
}
int result = longSubsequence(1,0);
System.out.println(result);
}
public static int longSubsequence(int i , int prev) {
if(i == n)return 0;
if(dp[i][prev] != -1)return dp[i][prev];
int choice1 = longSubsequence(i+1 , prev);
int choice2 = 0;
if(arr[i] >= arr[prev] && (prev + 1 == i)) {
choice2 = longSubsequence(i+1 , i) + 1;
}
return dp[i][prev] = Math.max(choice1, choice2);
}
}