当前位置:网站首页>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];
}
};
边栏推荐
- Zabbix_监控ssh/crond服务-微信告警
- Microsoft Word 教程「5」,如何在 Word 中更改頁邊距、創建新聞稿欄?
- 中国工科研究生200多篇英文论文中最常见的习惯(The Most Common Habits from more than 200 English Papers written by Gradua)
- Uni app custom navigation
- RuntimeError: Attempting to deserialize object on CUDA device 1 but torch. cuda. device_ count() is 1.
- Redis cluster form - sentry mode cluster and high availability mode cluster - redis learning notes 003
- An old programmer of about 10 years said: simple crud function enters the era of codeless development 1. Adding, deleting, modifying and checking interface information
- 【Educational Codeforces Round 120 (Rated for Div. 2)】C. Set or Decrease
- Zabbix_ Principle Architecture - installation and deployment - Custom monitoring
- CVPR 2022 Tsinghua University proposed unsupervised domain generalization (UDG)
猜你喜欢

AttributeError: module ‘collections‘ has no attribute ‘MutableMapping‘
![[FAQ] summary of common problems and solutions during the use of rest API interface of sports health service](/img/9e/9ce804d84fb8ec9221b7c10bbd6c36.jpg)
[FAQ] summary of common problems and solutions during the use of rest API interface of sports health service

Service management and communication, basic principle analysis

35岁被裁员,还能拥有美妙人生吗?

AttributeError: module ‘collections‘ has no attribute ‘MutableMapping‘

C语言 浮点数 储存形式

监控易打造“准生态”格局,赋能信创“平替”

中国工科研究生200多篇英文论文中最常见的习惯(The Most Common Habits from more than 200 English Papers written by Gradua)
![js基础及常考面试题之 [] == ![]结果为true, []==[]结果为false 详解](/img/42/bcda46a9297a544b44fea31be3f686.png)
js基础及常考面试题之 [] == ![]结果为true, []==[]结果为false 详解

vulnhub-The Planets: Earth
随机推荐
Zabbix_监控ssh/crond服务-微信告警
Redis集群形式--哨兵模式集群和高可用模式集群---Redis学习笔记003
knife4j配置使用直接拷贝即可
在阿里云国际上使用 OSS 和 CDN 部署静态网站
The national advanced computing industry innovation (Yichang) center was officially launched and jointly operated by Zhongke Shuguang and Shengzhe technologies
Li Kou 10821084 solution_ Question of SQL query type
使用环绕通知对目标方法进行增强—摘抄笔记
PDU session flow
ResourceNotFoundException : Unable to find resource
MySQL - common functions
堆叠条形图鼠标移入tooltip中提示过滤为0元素,实现自定义气泡
Service management and communication, basic principle analysis
How to realize face verification quickly and accurately?
SBC芯片35584数据手册预调节器翻译
如何使用物联网低代码平台进行工作表管理?
js基础及常考面试题之 [] == ![]结果为true, []==[]结果为false 详解
Build a BPMN modeling Web Service
canvas 高级功能(中)
国家先进计算产业创新(宜昌)中心正式落地 中科曙光、升哲科技联合运营
传音 Infinix 新机现身谷歌产品库,TECNO CAMON 19 预装 Android 13