当前位置:网站首页>Sword finger office secant
Sword finger office secant
2022-04-22 03:14:00 【Red fog】
subject : I'll give you a length of n Rope , Please cut the rope into m paragraph (m、n Are integers. ,n>1 also m>1). The length of each piece of rope is marked as k[0]、k[1]、……、k[m].k[0] * k[1]*…*k[m] 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 , At this point we get the maximum product 18.
/************************* Dynamic programming ******************************/
int maxProductAfterCutting_solution1(int length)
{
if (length < 2)
return 0;
if (length == 2)
return 1;
if (length == 3)
return 2;
int* products = (int*)malloc((length + 1)*sizeof(int));
assert(products != NULL);
memset(products, 0, (length + 1)*sizeof(int));
/**** The length is 0、1、2、3 Length of rope ********/
products[0] = 0;
products[1] = 1;
products[2] = 2;
products[3] = 3;
int max = 0;
int i = 0;
int j = 0;
for (i = 4; i <= length; i++)
{
max = 0;
for (j = 1; j <= i / 2; j++)
{
int product = products[j] * products[i - j];
if (max < product)
max = product;
products[i] = max;
}
}
max = products[length];
free(products);
products = NULL;
return max;
}
products[0] = 0;
products[1] = 1;
products[2] = 2;
products[3] = 3;
Why? products[2] = 2;products[3] = 3; Well ? because n=2,3 No more points .
版权声明
本文为[Red fog]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211350460629.html
边栏推荐
- c语言课程设计——基于链表的考场排位系统
- 第9章 内核同步介绍
- Sword finger offer special breakthrough version 93, longest Fibonacci series
- Golang dependency injection wire. When executing the wire command, an error is reported: bash: Wire: command not found
- Technology sharing | selenium ide use case recording
- leetcode:297. 二叉树的序列化与反序列化
- 2022-4-21作业
- 网络和多媒体知识(3)
- Interpretation of Flink's new features of fine-grained resource management
- Competition conference of the most fully quantified hardware facilities in the whole network
猜你喜欢

嘉戎技術深交所上市破發:公司市值41億 應收賬款2.8億

How to take sonar as an example to create a test step applicable to all enterprises

微信JSAPI支付方式与错误(当前页面的URL未注册,支付验证签名失败)

Technology sharing | selenium ide use case recording

苹果表主题图片爬取!

After four years of outsourcing, it was abandoned

OneFlow 如何做静态图的算子对齐任务

Flutter04 widget initial experience

kerberos认证协议

Alipay two faces: how to use UDP to achieve reliable transmission?
随机推荐
ESP32_GPIO输入、输出和中断
终于看清阿里,美团,京东这些企业的真面目了
Niu Ke's entry record of C language
golang依赖注入wire使用 执行wire命令时报错:bash: wire: command not found
Polyfill是什么?
Pytest automated testing framework (2)
72. 编辑距离
别人写的叫博客,自己写的叫笔记
Use xamarin to write a beautiful app login and registration interface
Interview with those stereotyped and boring interviewers
[wustctf2020] plain
【今晚七点】metaRTC的发展和应用场景探讨
【Laravel系列4.7】连接redis以及缓存应用
Ros2 learning notes (6) -- customized messages and services, control instruction optimization and online map change
Jiarong Technology Shenzhen Stock Exchange listed and discovered: The Value of Market of the company is 4.1 billion, and the Accounts receivables are 280 million.
Competition conference of the most fully quantified hardware facilities in the whole network
Buy a Tencent cloud server to play
Can Chrome browser + postman do interface testing like this?
Comparison of hex, Base64 and URLEncode coding schemes
kerberos認證協議