标签:http solution span loading col lazy 图片 i++ 假设
class Solution { public int maxCoins(int[] nums) { int n = nums.length + 2; int[] points = new int[n]; points[0] = 1; points[n-1] = 1; for(int i = 1; i <= n - 2; i++) points[i] = nums[i-1]; int[][] dp = new int[n][n]; // dp[i][j] 戳破(i,j)之间的气球最大多少分 假设最后一个戳破的是k // dp[i][j] = dp[i][k]+dp[k][j]+points[k]*points[i]*points[j] for(int i = n; i >= 0; i--) { for(int j = i + 2; j < n; j++) { for(int k = i + 1; k < j; k++) { dp[i][j] = Math.max(dp[i][j], dp[i][k] + dp[k][j] + points[k] * points[i] * points[j]); } } } return dp[0][n-1]; } }
标签:http solution span loading col lazy 图片 i++ 假设
原文地址:https://www.cnblogs.com/yonezu/p/13339459.html