4
代码如下:
public class he_ChangDui { public static void main(String[] args) { Scanner sc=new Scanner(System.in); //n为人数 int n=sc.nextInt(); int[] height=new int[n]; for (int i = 0; i < n; i++) { height[i]=sc.nextInt(); } int[] temp=new int[n]; for (int i = 0; i < n; i++) { int []a=new int[i]; for (int j = 0; j < i; j++) { a[j]=height[j]; } int[] b=new int[height.length-i]; for (int k = i; k < height.length; k++) { b[k-i]=height[height.length-k+i-1]; } temp[i]=handle(a)+handle(b); } Arrays.sort(temp); System.out.println(n-temp[n-1]); sc.close(); } public static int handle(int[] num) { if (num.length==0) { return 0; } int[] curMax=new int[num.length]; for (int i = 0; i < num.length; i++) { curMax[i]=1; for (int j = 0; j < i; j++) { if (num[i]>num[j]&&curMax[i]<curMax[j]+1) { curMax[i]=curMax[j]+1; } } } Arrays.sort(curMax); return curMax[num.length-1]; } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/zzc8265020/article/details/46923873