当前位置:网站首页>割舍绳子/整数分割
割舍绳子/整数分割
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];
}
};
边栏推荐
- 刷脸认证如何实现人脸又快又准完成校验?
- How do big factories write data analysis reports?
- Analysis of epidemic situation in Shanghai based on improved SEIR model
- Zabbix_ Monitoring ssh/crond Service - wechat alarm
- 高考后选择哪所学校?VR全景校园全方位展示
- When the college entrance examination is opened, VR panorama can see the test site in this way
- VR全景作品中各式各样的嵌入功能是如何做到的?
- RT-Thread Smart Win10 64位下编译环境的搭建
- 【技术碎片】重名文件 加后缀重命名过滤实现
- seata 还是不支持sqlserver吗?
猜你喜欢

京东发布基于张量网络加速的大规模、分布式量子机器学习平台TeD-Q
![[enter textbook latex record]](/img/f0/5ca60f0894d4ae544e7399d18a3a42.png)
[enter textbook latex record]

Spark ShuffleManager

高考开启,VR全景可以这样看考点

KP522201A采用 SOT23-6 封装的 4.5V 至 17V 输入、2A 输出、600kHz 同步降压转换器

Zabbix_ Principle Architecture - installation and deployment - Custom monitoring

When the college entrance examination is opened, VR panorama can see the test site in this way

How to add aggregation hotspots in VR panorama? How to add a content module?

PDU session flow

如何在VR全景作品中添加独立热点?
随机推荐
【legendre】多项式
Mongodb 唯一索引
Fs4100 lithium battery charging management IC input 12V to 8.4v charging IC
Zabbix_ Monitoring ssh/crond Service - wechat alarm
Recent work
Microsoft Word 教程「5」,如何在 Word 中更改页边距、创建新闻稿栏?
I drew several exquisite charts with plotly, which turned out to be beautiful!!
高考开启,VR全景可以这样看考点
vulnhub-The Planets: Earth
Complete knapsack problem and optimization tips
Zabbix_ Principle Architecture - installation and deployment - Custom monitoring
ResourceNotFoundException : Unable to find resource
Is it safe to open an account online for futures? How to open an account specifically
首批!青藤通过信通院CWPP能力评估检验
C pointer (interview classic topic exercise)
Rotated Sorted Array旋转排序数组相关题
京东发布基于张量网络加速的大规模、分布式量子机器学习平台TeD-Q
VR全景如何应用在家装中?体验真实的家装效果
批量检测不同url的指定端口(py脚本)
How to increase the monthly salary of software testing from 10K to 30K? Only automated testing can do it