当前位置:网站首页>Cut rope / integer split
Cut rope / integer split
2022-06-10 20:40:00 【Engineering students who like history】
When i > 2 when , Let's say we have a positive integer i When the first positive integer is split j(1<=j<i - 1, Because from 2 Start ) Then there are two options :
- take i Split into j and i-j And , And i-j Cannot be split into multiple positive integers , The product at this point is j*(i-j)
- take i Split into j and (i-j) And , And i-j You can continue to split into multiple positive integers , The achievement at this time is j*dp[i-j]
dp[i] = max(dp[i], max((i - j) * j, dp[i - j] * j));Just take dp[i] The maximum of
class Solution {
public:
int integerBreak(int n) {
vector<int> dp(n + 1);
dp[2] = 1;
for (int i = 3; i <= n ; i++) {
for (int j = 1; j < i - 1; j++) {
dp[i] = max(dp[i], max((i - j) * j, dp[i - j] * j));
}
}
return dp[n];
}
};
边栏推荐
- MBA-day21 线性规划问题
- 【录入课本latex记录】
- The old programmer said: stop translating the world, developers should return to programming
- mysql基础篇之mysql在已有表中添加自动增加的主键(或任意一个字段)
- ESP8266 系统环境搭建
- Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE tha
- Is Zhongyan futures reliable? Is it a regular futures company? Is it safe to open an account?
- Qualcomm qc2.0 fast charging intelligent identification IC fp6719
- 农产品期货开户的条件是什么?现在开户的手续费是多少?
- [observation] shengteng Zhixing: scene driven, innovation first, press the "acceleration key" for Intelligent Transportation
猜你喜欢

PDU会话流程

pdf.js-----js解析pdf文件实现预览,并获取pdf文件中的内容(数组形式)

Kp522201a adopts SOT23-6 encapsulated 4.5V to 17V input, 2A output, 600kHz synchronous step-down converter

测试apk-异常管控netLocation攻击者开发

vulnhub-The Planets: Earth

canvas 高级功能(上)
![js基础及常考面试题之 [] == ![]结果为true, []==[]结果为false 详解](/img/42/bcda46a9297a544b44fea31be3f686.png)
js基础及常考面试题之 [] == ![]结果为true, []==[]结果为false 详解
![[observation] shengteng Zhixing: scene driven, innovation first, press the](/img/53/29f5fd8b869087bafbe74849329c84.jpg)
[observation] shengteng Zhixing: scene driven, innovation first, press the "acceleration key" for Intelligent Transportation

观点丨Play and Earn 会让加密游戏误入歧途

localhost和127.0.0.1的区别?
随机推荐
Uni app custom navigation
pdf.js-----js解析pdf文件实现预览,并获取pdf文件中的内容(数组形式)
canvas 高级功能(上)
在阿里云国际上使用 OSS 和 CDN 部署静态网站
Canvas advanced functions (medium)
The national advanced computing industry innovation (Yichang) center was officially launched and jointly operated by Zhongke Shuguang and Shengzhe technologies
「Bug」问题分析 RuntimeError:which is output 0 of ReluBackward0
利用阿里云国际购买的服务器搭建个人网站步骤
P5723 【深基4.例13】质数口袋
自定义日期组件,左右按钮控制向前或向后翻年、翻月、翻周、翻日
知识图谱/关系可视化
Li Kou 10821084 solution_ Question of SQL query type
table设置超出部分隐藏,鼠标移上去显示全部
Enhance the target method with surround notifications - extract notes
Cloud native community boss blog
Service management and communication, basic principle analysis
【legendre】多项式
[observation] shengteng Zhixing: scene driven, innovation first, press the "acceleration key" for Intelligent Transportation
Four methods to obtain the position index of the first n values of the maximum and minimum values in the list
The new audio infinix machine appears in the Google product library, and Tecno CaMon 19 is pre installed with Android 13