当前位置:网站首页>312. poke the balloon
312. poke the balloon
2022-06-23 07:08:00 【Graduation_ Design】
Preface
C++ It's a high-level programming language , from C Language expansion and upgrading , As early as 1979 By Benjani · Strauss LUP is AT&T Developed by Bell studio .
C++ Both can be carried out C Process programming of language , It can also be used for object-based programming characterized by abstract data types , It can also carry out object-oriented programming characterized by inheritance and polymorphism .C++ Good at object-oriented programming at the same time , You can also do process based programming .
C++ Have the practical characteristics of computer operation , At the same time, it is also committed to improving the programming quality of large-scale programs and the problem description ability of programming languages .
Java Is an object-oriented programming language , Not only absorbed C++ The advantages of language , It's abandoned C++ The incomprehensible inheritance in 、 Concepts such as pointer , therefore Java Language has two characteristics: powerful and easy to use .Java As the representative of static object-oriented programming language , Excellent implementation of object-oriented theory , Allow programmers to do complex programming in an elegant way of thinking .
Java It's simple 、 object-oriented 、 Distributed 、 Robustness, 、 Security 、 Platform independence and portability 、 Multithreading 、 Dynamic and so on .Java Can write desktop applications 、Web Applications 、 Distributed system and embedded system applications, etc .
Python By Guido of the Dutch Society for mathematical and computer science research · Van rosum On 1990 It was designed in the early 's , As a course called ABC A substitute for language .Python Provides efficient advanced data structure , It's also a simple and effective way of object-oriented programming .Python Syntax and dynamic types , And the nature of interpretative language , Make it a programming language for scripting and rapid application development on most platforms , With the continuous update of the version and the addition of new language features , Gradually used for independent 、 Development of large projects .
Python The interpreter is easy to extend , have access to C Language or C++( Or something else can be done through C Calling language ) Expand new functions and data types .Python It can also be used as an extensible programming language in customizable software .Python Rich library of standards , Provides source code or machine code for each major system platform .
2021 year 10 month , Compiler for language popularity index Tiobe take Python Crowned the most popular programming language ,20 Put it in... For the first time in years Java、C and JavaScript above .
describe
Yes n A balloon , The number is 0 To n - 1, Each balloon is marked with a number , There are arrays of these numbers nums in .
Now I ask you to prick all the balloons . Pierce the second i A balloon , You can get nums[i - 1] * nums[i] * nums[i + 1] Coin . there i - 1 and i + 1 For and on behalf of i The serial number of the two adjacent balloons . If i - 1 or i + 1 Beyond the bounds of the array , Then think of it as a number for 1 The balloon .
Find the maximum number of coins you can get .
Example 1:
Input :nums = [3,1,5,8]
Output :167
explain :
nums = [3,1,5,8] --> [3,5,8] --> [3,8] --> [8] --> []
coins = 3*1*5 + 3*5*8 + 1*3*8 + 1*8*1 = 167
Example 2:
Input :nums = [1,5]
Output :10
class Solution {
public int[][] rec;
public int[] val;
public int maxCoins(int[] nums) {
int n = nums.length;
val = new int[n + 2];
for (int i = 1; i <= n; i++) {
val[i] = nums[i - 1];
}
val[0] = val[n + 1] = 1;
rec = new int[n + 2][n + 2];
for (int i = 0; i <= n + 1; i++) {
Arrays.fill(rec[i], -1);
}
return solve(0, n + 1);
}
public int solve(int left, int right) {
if (left >= right - 1) {
return 0;
}
if (rec[left][right] != -1) {
return rec[left][right];
}
for (int i = left + 1; i < right; i++) {
int sum = val[left] * val[i] * val[right];
sum += solve(left, i) + solve(i, right);
rec[left][right] = Math.max(rec[left][right], sum);
}
return rec[left][right];
}
}
边栏推荐
- redux Actions may not have an undefined “type“ property. Have you misspelled a constant?
- 899. 有序队列
- [daily training] 513 Find the value in the lower left corner of the tree
- 2121. 相同元素的间隔之和-哈希表法
- C DPI adaptation problem
- MySQL function
- 407-栈与队列(232.用栈实现队列、225. 用队列实现栈)
- asp. Net file download demo and related problems
- 为什么TCP协议是三次握手而不是两次?
- [project training] multi segment line expanded to parallel line
猜你喜欢
随机推荐
[saison de remise des diplômes · technologie agressive er] votre choix, agenouillez - vous et partez
315. calculate the number of elements on the right that are smaller than the current element
图解三次握手四次挥手,小白都能看懂
MySQL重做日志 redo log
[project training] multi segment line expanded to parallel line
paddle版本问题
小白投资理财必看:图解基金买入与卖出规则
309. 最佳买卖股票时机含冷冻期
300. 最长递增子序列
excel高级绘图技巧100讲(八)-Excel绘制WIFI图
[shell] tree command
406 double pointer (27. remove elements, 977. square of ordered array, 15. sum of three numbers, 18. sum of four numbers)
406-双指针(27. 移除元素、977.有序数组的平方、15. 三数之和、18. 四数之和)
关于五险一金你需要知道的事情
301. 删除无效的括号
Traversal of binary tree and related knowledge
901. 股票价格跨度
Idea automatically generates serialVersionUID
[system] right click the desktop icon. After turning around, the Explorer will crash and the desktop will be refreshed
Xxl-sso enables SSO single sign on


![[STL] summary of map usage of associated containers](/img/1d/1b6488ea47face0548500b1e1ec60d.png)






