import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int[] ball = new int[201]; for (int i = 1; i <= n; i++) { ball[i] = input.nextInt(); //模拟环 ball[n+i] = ball[i]; } //dp int[][] maxE = new int[201][201]; int result = 0; for (int i = 2; i < 2*n; i++) { //右端点 for (int j = i - 1; j > 0 && i - j < n; j-- ) { //左端点 for (int k = j; k < i; k++) maxE[j][i] = Math.max(maxE[j][i], maxE[j][k] + maxE[k+1][i] + ball[j]*ball[k+1]*ball[i+1]); if (result < maxE[j][i]) result = maxE[j][i]; } } System.out.println(result); } }
解题思路:
注意事项:
参考代码:
0.0分
2 人评分