当前位置:网站首页>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;
}
};
边栏推荐
- [exercise 7] [Database Principle]
- Powerful avatar making artifact wechat applet
- The best shortcut is no shortcut
- 01 three solutions to knapsack problem (greedy dynamic programming branch gauge)
- 剑指 Offer 12. 矩阵中的路径
- Tianyi ty1208-z brush machine detailed tutorial (free to remove)
- 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
- Ten workplace rules
- Detailed explanation of the most complete constraintlayout in history
- 【R】【密度聚类、层次聚类、期望最大化聚类】
猜你喜欢

Sword finger offer14 the easiest way to cut rope

强大的头像制作神器微信小程序

剑指 Offer 14- II. 剪绳子 II

Leetcode234 palindrome linked list

GaN图腾柱无桥 Boost PFC(单相)七-PFC占空比前馈
![[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)](/img/45/c2d7934b886d8090373ca9e6e23c97.gif)
[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)

基于同步坐标变换的谐波电流检测

initial、inherit、unset、revert和all的区别

Node.js: express + MySQL的使用

Social community forum app ultra-high appearance UI interface
随机推荐
ORM use of node -serialize
【数据库原理复习题】
解决 System has not been booted with systemd as init system (PID 1). Can‘t operate.
Brief introduction to mvcc
Sword finger offer14 the easiest way to cut rope
Bert running error: attributeerror: module'tensorflow contrib. tpu' has no attribute 'InputPipelineConfig'
C graphical tutorial (Fourth Edition)_ Chapter 13 entrustment: what is entrustment? P238
luoguP3694邦邦的大合唱站队
C graphical tutorial (Fourth Edition)_ Chapter 15 interface: interfacesamplep271
Application of ncnn neural network computing framework in orange school orangepi 3 lts development board
Do you feel like you've learned something and forgotten it?
[exercise 7] [Database Principle]
A large select drop-down box, village in Chaoyang District
GaN图腾柱无桥 Boost PFC(单相)七-PFC占空比前馈
2022-02-09 survey of incluxdb cluster
Oh my Zsh + TMUX installation
初入职场,如何快速脱颖而出?
剑指 Offer 14- II. 剪绳子 II
Dix règles de travail
Export the entire Oracle Database