# 2017阿里编程测试题

4
2
3
0
3

12

import java.util.*;

public class Main {

/** 请完成下面这个函数，实现题目要求的功能 **/
/** 当然，你也可以不按照这个模板来作答，完全按照自己的想法来 ^-^  **/
static int maxScore(int[] score) {
int scoreMax=0;

return scoreMax;
}

public static void main(String[] args){
Scanner in = new Scanner(System.in);
int res;

int _score_size = 0;
//输入靶的个数
_score_size = Integer.parseInt(in.nextLine().trim());
int[] _score = new int[_score_size];
int _score_item;
for(int _score_i = 0; _score_i < _score_size; _score_i++) {
//依次输入每个靶的得分,
_score_item = Integer.parseInt(in.nextLine().trim());
_score[_score_i] = _score_item;
}

res = maxScore(_score);
System.out.println(String.valueOf(res));

}
}

import java.util.ArrayList;

import java.util.Scanner;

public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int res;

int _score_size = 0;
//输入靶的个数
_score_size = Integer.parseInt(in.nextLine().trim());
int[] _score = new int[_score_size];
int _score_item;
for(int _score_i = 0; _score_i < _score_size; _score_i++) {
//依次输入每个靶的得分,
_score_item = Integer.parseInt(in.nextLine().trim());
_score[_score_i] = _score_item;
}

res = getMax(_score);
System.out.println(String.valueOf(res));
}

private static int getMax(int [] num){
ArrayList<Integer> arrayList=new ArrayList<>();
for (int i = 0; i < num.length; i++) {
if (i==num.length-1&num[i]!=0){
}else if (num[i]==0){
}else if (i==0){
}
}
int sum=0;
for (int i=0;i<arrayList.size()-1;i++){
System.out.println("开始位置:"+arrayList.get(i)+"结束位置:"+arrayList.get(i+1));
sum+=getMaxScore(num,arrayList.get(i),arrayList.get(i+1));
}
return sum;
}

private static int getMaxScore(int[] num,int start,int end) {

int[] newNum=new int[end-start+3];
int n=1;

for (int i = start; i <=end; i++) {
newNum[n++]=num[i];
}

newNum[0]=newNum[n++]=1;

int[][] dp=new int[n][n];
//用于记录击中顺序
int[][] burstorders = new int[n][n];
for (int disappear  = 2; disappear <n ; disappear++) {
for (int left = 0; left < n - disappear; left++) {
int right=left+disappear;
for (int i = left+1; i < right; i++) {
//如何知道扎破顺序
int score=dp[left][i]+newNum[left]*newNum[i]*newNum[right]+dp[i][right];
if(score>dp[left][right]){
dp[left][right]=score;
}

}
}
}
return dp[0][n-1];
}
}