当前位置:网站首页>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;
}
};
边栏推荐
- C graphical tutorial (Fourth Edition)_ Chapter 18 enumerator and iterator: enumerator samplep340
- The latest version of lottery blind box operation version
- 2022-01-27 redis cluster technology research
- 剑指 Offer 16. 数值的整数次方
- C graphical tutorial (Fourth Edition)_ Chapter 20 asynchronous programming: examples - using asynchronous
- Redhat5 installing socket5 proxy server
- Two solutions of leetcode101 symmetric binary tree (recursion and iteration)
- 【数据库原理及应用教程(第4版|微课版)陈志泊】【第六章习题】
- How to get user location in wechat applet?
- Swift bit operation exercise
猜你喜欢
并网-低电压穿越与孤岛并存分析
ncnn神經網絡計算框架在香柳丁派OrangePi 3 LTS開發板中的使用介紹
我的创作纪念日:五周年
Day 1 of kotlin learning: simple built-in types of kotlin
[network counting] Chapter 3 data link layer (2) flow control and reliable transmission, stop waiting protocol, backward n frame protocol (GBN), selective retransmission protocol (SR)
When the R language output rmarkdown is in other formats (such as PDF), an error is reported, latex failed to compile stocks Tex. solution
最新版抽奖盲盒运营版
Quick learning 1.8 front and rear interfaces
Seven second order ladrc-pll structure design of active disturbance rejection controller
Gan totem column bridgeless boost PFC (single phase) seven PFC duty cycle feedforward
随机推荐
最新版抽奖盲盒运营版
I'm too lazy to write more than one character
An example of newtonjason
Glide question you cannot start a load for a destroyed activity
【数据库原理复习题】
Loan calculator my pressure is high
ImportError: No module named examples. tutorials. mnist
Tianyi ty1208-z brush machine detailed tutorial (free to remove)
It feels great to know you learned something, isn‘t it?
[review questions of database principles]
SLF4J 日志门面
Express abstract classes and methods
自抗扰控制器七-二阶 LADRC-PLL 结构设计
十條職場規則
2022-01-27 redis cluster technology research
2022-02-10 introduction to the design of incluxdb storage engine TSM
initial、inherit、unset、revert和all的区别
[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.
Sword finger offer14 the easiest way to cut rope