当前位置:网站首页>Sword finger offer 14- ii Cut rope II
Sword finger offer 14- ii Cut rope II
2022-07-03 12:59:00 【Hiccup~~~~】
The finger of the sword Offer 14- II. Cut the rope II
Medium difficulty 189
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.
The answer needs to be modelled 1e9+7(1000000007), If the initial result of calculation is :1000000008, Please return 1.
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 <= 1000
Ideas
- The remainder of large numbers =》 Dynamic programming cannot be used =》 After taking the surplus max Functions cannot be used to compare sizes
- The finger of the sword Offer 14- I. Cut the rope Print the results

- Sum up the law

Code
class Solution {
public:
int cuttingRope(int n) {
long res=1;
if(n==1||n==2) return 1;
else if(n==3) return 2;
// Disassemble into several 3
while(n/3>1){
res*=3;
res%=1000000007;
n-=3;
}
if(n%3==1) res*=4;
else res=res*3*(n%3?n%3:1);
return res%1000000007;
}
};
边栏推荐
- Gan totem column bridgeless boost PFC (single phase) seven PFC duty cycle feedforward
- [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
- Sword finger offer14 the easiest way to cut rope
- [comprehensive question] [Database Principle]
- The upward and downward transformation of polymorphism
- Grid connection - Analysis of low voltage ride through and island coexistence
- C graphical tutorial (Fourth Edition)_ Chapter 15 interface: interfacesamplep271
- 【数据库原理及应用教程(第4版|微课版)陈志泊】【第三章习题】
- The best shortcut is no shortcut
- CVPR 2022 图像恢复论文
猜你喜欢

How to get user location in wechat applet?

T430 toss and install OS majave 10.14
![[review questions of database principles]](/img/c3/81d192a40bcc4f5d72fcbe76c708bb.png)
[review questions of database principles]

2022-02-09 survey of incluxdb cluster

Glide question you cannot start a load for a destroyed activity

Attack and defense world mobile--ph0en1x-100

【Colab】【使用外部数据的7种方法】

并网-低电压穿越与孤岛并存分析

最新版盲盒商城thinkphp+uniapp
![[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
随机推荐
How to stand out quickly when you are new to the workplace?
阿里 & 蚂蚁自研 IDE
Swift bit operation exercise
Oh my Zsh + TMUX installation
Kotlin - 改良装饰者模式
initial、inherit、unset、revert和all的区别
【Colab】【使用外部数据的7种方法】
How to get user location in wechat applet?
最新版盲盒商城thinkphp+uniapp
Xctf mobile--app3 problem solving
剑指 Offer 16. 数值的整数次方
Exploration of sqoop1.4.4 native incremental import feature
【综合题】【数据库原理】
【数据库原理及应用教程(第4版|微课版)陈志泊】【SQLServer2012综合练习】
A large select drop-down box, village in Chaoyang District
剑指 Offer 14- II. 剪绳子 II
The solution to change the USB flash disk into a space of only 2m
Swift5.7 extend some to generic parameters
剑指 Offer 12. 矩阵中的路径
Method overloading and rewriting