当前位置:网站首页>Sword finger offer 14- I. cut rope
Sword finger offer 14- I. cut rope
2022-07-03 12:59:00 【Hiccup~~~~】
The finger of the sword Offer 14- I. Cut the rope
I'll give you a length of n The rope of , Please cut the rope to the whole length m paragraph (m、n Are integers. ,n>1 also m>1), The length of each rope is recorded as k[0],k[1]…k[m-1] . Excuse me, k[0]k[1]…*k[m-1] What's the maximum possible product ? for example , When the length of the rope is 8 when , We cut it into lengths of 2、3、3 Three paragraphs of , The maximum product we get here is 18.
Example 1:
Input : 2
Output : 1
explain : 2 = 1 + 1, 1 × 1 = 1
Example 2:
Input : 10
Output : 36
explain : 10 = 3 + 3 + 4, 3 × 3 × 4 = 36
Tips :
2 <= n <= 58
Ideas
Dynamic programming
Recurrence :a[i]=max(a[i], max( (i-j),a[i-j] ) * max( j,a[j] ));
- max( Previous value , Current updated value )
- Current updated value =[i-j] The maximum value of the range * [0-j] Maximum range
Code
class Solution {
public:
int cuttingRope(int n) {
vector<int> a(60);
a[0]=0;
a[1]=1;
for(int i=2;i<=n;i++){
for(int j=1;j<i;j++){
a[i]=max(a[i],max( (i-j),a[i-j] )*max( j,a[j] ));
}
// printf("%d--%d\n",i,a[i]);
}
return a[n];
}
};
边栏推荐
- The foreground uses RSA asymmetric security to encrypt user information
- 十條職場規則
- 4. Wireless in vivo nano network: electromagnetic propagation model and key points of sensor deployment
- Pytext training times error: typeerror:__ init__ () got an unexpected keyword argument 'serialized_ options'
- C graphical tutorial (Fourth Edition)_ Chapter 15 interface: interfacesamplep271
- Deeply understand the mvcc mechanism of MySQL
- Do you feel like you've learned something and forgotten it?
- Enter the length of three sides of the triangle through the user, and calculate the area of the triangle, where the length is a real number
- 【数据库原理及应用教程(第4版|微课版)陈志泊】【第七章习题】
- CNN MNIST handwriting recognition
猜你喜欢

Xctf mobile--app3 problem solving
![[combinatorics] permutation and combination (the combination number of multiple sets | the repetition of all elements is greater than the combination number | the derivation of the combination number](/img/9d/6118b699c0d90810638f9b08d4f80a.jpg)
[combinatorics] permutation and combination (the combination number of multiple sets | the repetition of all elements is greater than the combination number | the derivation of the combination number

解决 System has not been booted with systemd as init system (PID 1). Can‘t operate.

最新版盲盒商城thinkphp+uniapp

对业务的一些思考

Node.js: express + MySQL的使用

Gan totem column bridgeless boost PFC (single phase) seven PFC duty cycle feedforward

Xctf mobile--rememberother problem solving

Huffman coding experiment report

Differences between initial, inherit, unset, revert and all
随机推荐
Enable SASL authentication for memcached
关于CPU缓冲行的理解
【数据库原理及应用教程(第4版|微课版)陈志泊】【第三章习题】
强大的头像制作神器微信小程序
Kotlin - 改良装饰者模式
context. Getexternalfilesdir() is compared with the returned path
Differences between initial, inherit, unset, revert and all
Ali & ant self developed IDE
2022-01-27 use liquibase to manage MySQL execution version
C graphical tutorial (Fourth Edition)_ Chapter 20 asynchronous programming: examples - cases without asynchronous
The solution to change the USB flash disk into a space of only 2m
Node. Js: use of express + MySQL
Differences and connections between final and static
An example of newtonjason
Swift bit operation exercise
C graphical tutorial (Fourth Edition)_ Chapter 13 entrustment: delegatesamplep245
Seven second order ladrc-pll structure design of active disturbance rejection controller
Oh my Zsh + TMUX installation
Social community forum app ultra-high appearance UI interface
CVPR 2022 图像恢复论文