当前位置:网站首页>割舍绳子/整数分割
割舍绳子/整数分割
2022-06-10 19:24:00 【喜欢历史的工科生】
当 i > 2时,假设对正整数i拆分出的第一个正整数时j(1<=j<i - 1,因为从2开始)那么有以下两种方案:
- 将i拆分成j和i-j的和,且i-j不能再拆分成多个正整数,此时的乘积是j*(i-j)
- 将i拆分成j和(i-j)的和,且i-j可以继续拆分成多个正整数,此时的成及是j*dp[i-j]
dp[i] = max(dp[i], max((i - j) * j, dp[i - j] * j));只是取dp[i]的最大值
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];
}
};
边栏推荐
- 2022 Devops roadmap | medium
- 8.4v双节锂电池专业充电ic(FS4062A)
- Kp522201a adopts SOT23-6 encapsulated 4.5V to 17V input, 2A output, 600kHz synchronous step-down converter
- Microsoft Word 教程「5」,如何在 Word 中更改页边距、创建新闻稿栏?
- 国家先进计算产业创新(宜昌)中心正式落地 中科曙光、升哲科技联合运营
- VR全景如何应用在家装中?体验真实的家装效果
- PDU session flow
- Redis集群形式--哨兵模式集群和高可用模式集群---Redis学习笔记003
- When can Flink support the SQL client mode? When can I specify the applicati for submitting tasks to yarn
- Soft deletion of data - when? How to realize it?
猜你喜欢

First batch! Sinomenine has passed CWPP capability assessment and inspection of Xintong Institute

One question to explain the past and present life of dynamic planning

During the college entrance examination this year, all examination sites were in good order, and no sensitive cases affecting safety occurred

【观察】昇腾智行:场景驱动,创新先行,为智慧交通按下“加速键”

高考结束,VR全景云游为你展现景区的美好风光

Zabbix_原理架构-安装部署-自定义监控

Which school do you choose after the college entrance examination? VR panoramic campus all-round display
![[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

How to add independent hotspots in VR panoramic works?

FPGA state machine
随机推荐
How to apply VR panorama in home decoration? Experience the real home decoration effect
MBA-day21 线性规划问题
When the college entrance examination is opened, VR panorama can see the test site in this way
Basic instructions for ads and AXD
Problem with makefile: unable to detect file updates
Zabbix_监控ssh/crond服务-微信告警
2022 年 DevOps 路线图|Medium
vulnhub-The Planets: Earth
【观察】昇腾智行:场景驱动,创新先行,为智慧交通按下“加速键”
Detailed interpretation of tph-yolov5 | making small targets in target detection tasks invisible
Fs4060a is a 4.2v/3a charging IC
How to realize face verification quickly and accurately?
mysql服务启动失败
Esp8266 system environment setup
Zabbix_ Principle Architecture - installation and deployment - Custom monitoring
HW blue team intermediate interview reply
【FAQ】运动健康服务REST API接口使用过程中常见问题和解决方法总结
How do various embedded functions in VR panoramic works be achieved?
Standing at such a time node today, we may have a clearer understanding of the industrial Internet
用 Plotly 绘制了几张精湛的图表,美翻了!!