当前位置:网站首页>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;
}
};
边栏推荐
- Dojo tutorials:getting started with deferrals source code and example execution summary
- Analysis of a music player Login Protocol
- 对业务的一些思考
- 【综合题】【数据库原理】
- 剑指 Offer 14- I. 剪绳子
- Tensorflow binary installation & Failure
- The best shortcut is no shortcut
- C graphical tutorial (Fourth Edition)_ Chapter 15 interface: interfacesamplep268
- Pytext training times error: typeerror:__ init__ () got an unexpected keyword argument 'serialized_ options'
- C graphical tutorial (Fourth Edition)_ Chapter 20 asynchronous programming: examples - cases without asynchronous
猜你喜欢

Solve the problem of VI opening files with ^m at the end

自抗扰控制器七-二阶 LADRC-PLL 结构设计

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

Harmonic current detection based on synchronous coordinate transformation

Ali & ant self developed IDE

如何在微信小程序中获取用户位置?

GaN图腾柱无桥 Boost PFC(单相)七-PFC占空比前馈

Node. Js: use of express + MySQL

Two solutions of leetcode101 symmetric binary tree (recursion and iteration)

studio All flavors must now belong to a named flavor dimension. Learn more
随机推荐
The upward and downward transformation of polymorphism
C graphical tutorial (Fourth Edition)_ Chapter 20 asynchronous programming: examples - using asynchronous
【综合题】【数据库原理】
[judgment question] [short answer question] [Database Principle]
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
2022-01-27 redis cluster technology research
剑指 Offer 14- II. 剪绳子 II
2022-02-11 practice of using freetsdb to build an influxdb cluster
Application of ncnn neural network computing framework in orange school orangepi 3 lts development board
Brief introduction to mvcc
Node.js: express + MySQL的使用
SSH登录服务器发送提醒
OpenHarmony应用开发之ETS开发方式中的Image组件
Kung Fu pays off, and learning is done
Differences and connections between final and static
Application of ncnn Neural Network Computing Framework in Orange Pi 3 Lts Development Board
[exercise 7] [Database Principle]
强大的头像制作神器微信小程序
解决 System has not been booted with systemd as init system (PID 1). Can‘t operate.
It feels great to know you learned something, isn‘t it?