当前位置: 首页 > news >正文

松原网站建设公司网络营销推广案例

松原网站建设公司,网络营销推广案例,用易语言做攻击网站软件下载,牛商网网站建设1、题目描述 给你一根长度为 n 的绳子,请把绳子剪成整数长度的 m 段(m、n都是整数,n>1并且m>1),每段绳子的长度记为 k[0],k[1]…k[m - 1] 。请问 k[0]k[1]…*k[m - 1] 可能的最大乘积是多少?例如&am…

1、题目描述

给你一根长度为 n 的绳子,请把绳子剪成整数长度的 m 段(m、n都是整数,n>1并且m>1),每段绳子的长度记为 k[0],k[1]…k[m - 1] 。请问 k[0]k[1]…*k[m - 1] 可能的最大乘积是多少?例如,当绳子的长度是8时,我们把它剪成长度分别为2、3、3的三段,此时得到的最大乘积是18。
答案需要取模 1e9+7(1000000007),如计算初始结果为:1000000008,请返回 1。
示例 1
输入: 2
输出: 1
解释: 2 = 1 + 1, 1 × 1 = 1
示例 2:
输入: 10
输出: 36
解释: 10 = 3 + 3 + 4, 3 × 3 × 4 = 36
(这个题与前一个题的区别是,这个题大数运算,不能用动态规划)

2、VS2019上运行

使用贪心算法
贪心算法

#include <iostream>
using namespace std;class Solution {
public:int cuttingRope(int n) {// 如果 n 小于等于 3,则直接返回 n - 1,因为长度为 2 和 3 时,不剪切乘积最大。if (n <= 3) return n - 1;// 如果 n 等于 4,则直接返回 4,因为长度为 4 时,将其剪成 2x2 的乘积最大。if (n == 4) return 4;long res = 1; // 初始化结果变量为 1,用于计算乘积。while (n > 4){res *= 3;  // 每次乘以 3res %= 1000000007;  // 取模防止溢出n -= 3;  // n 减去 3}// 最后 n 的值只有可能是:2、3、4。// 而 2、3、4 能得到的最大乘积恰恰就是自身值// 因为 2、3 不需要再剪了(剪了反而变小);// 4 剪成 2x2 是最大的,2x2 恰恰等于 4return res * n % 1000000007;}
};int main() {Solution sol;int n;cout << "Enter the length of the rope: ";cin >> n;int maxProduct = sol.cuttingRope(n);cout << "Maximum product of the rope after cutting is: " << maxProduct << endl;return 0;
}

Enter the length of the rope: 10
Maximum product of the rope after cutting is: 36

3、解题思路

  • 为什么选择剪成长度为 3 的绳子?这涉及到一个数学推导:
  • 假设将绳子剪成长度为 x 和 n - x,其中 x 为一段的长度,n 为总绳子长度。我们希望求得这种剪法下的乘积最大值。
  • 可以证明,当 x = n/3 时,乘积最大。对于长度为 n 的绳子:
  • 1.当 n = 3k 时,我们将绳子分成长度为 x = n/3 = k 的三段,此时乘积为 x^3 = (n/3)^3。
    2.当 n = 3k + 1 时,我们将绳子分成长度为 x = n/3 = k 和 x + 1 = k + 1 的两段,此时乘积为 x * (x + 1)^2 = (n/3) * ((n/3) + 1)^2。
    3.当 n = 3k + 2 时,我们将绳子分成长度为 x = n/3 = k 和 x + 2 = k + 2 的两段,此时乘积为 x * (x + 2) = (n/3) * ((n/3) + 2)。
    可以观察到,在 n mod 3 = 0, 1, 2 时,乘积都可以表示为 x 的形式乘以某个因子。而要使乘积最大,我们需要选择 x 为整数,因此选择 x 最接近 n/3,并且取整数部分,即 x = floor(n/3)。

文章转载自:
http://dinncofiacre.tqpr.cn
http://dinncosmallshot.tqpr.cn
http://dinncoswimmy.tqpr.cn
http://dinncolascar.tqpr.cn
http://dinncogland.tqpr.cn
http://dinncoonside.tqpr.cn
http://dinncodithyrambic.tqpr.cn
http://dinncoprobang.tqpr.cn
http://dinncoderrick.tqpr.cn
http://dinncopardi.tqpr.cn
http://dinncotorture.tqpr.cn
http://dinncoinnumerably.tqpr.cn
http://dinncoambulance.tqpr.cn
http://dinncoprofessoriate.tqpr.cn
http://dinncounconsciously.tqpr.cn
http://dinncohappenchance.tqpr.cn
http://dinncocapable.tqpr.cn
http://dinncotrinitroglycerin.tqpr.cn
http://dinncosubpena.tqpr.cn
http://dinncoembolden.tqpr.cn
http://dinncobelgrade.tqpr.cn
http://dinncodulcimer.tqpr.cn
http://dinncodigamous.tqpr.cn
http://dinncochondriosome.tqpr.cn
http://dinncosaloonist.tqpr.cn
http://dinncodetribalize.tqpr.cn
http://dinncohomoerotism.tqpr.cn
http://dinncolicet.tqpr.cn
http://dinncosparseness.tqpr.cn
http://dinncojunctural.tqpr.cn
http://dinncoalthea.tqpr.cn
http://dinncolamely.tqpr.cn
http://dinncopassingly.tqpr.cn
http://dinncocoordinator.tqpr.cn
http://dinncoseedpod.tqpr.cn
http://dinncoscholastic.tqpr.cn
http://dinncopatienthood.tqpr.cn
http://dinncosigmoidostomy.tqpr.cn
http://dinncocacholong.tqpr.cn
http://dinncophenomenistic.tqpr.cn
http://dinncoprisere.tqpr.cn
http://dinncoposthypnotic.tqpr.cn
http://dinncogladiator.tqpr.cn
http://dinncoscrewloose.tqpr.cn
http://dinncodeintegro.tqpr.cn
http://dinncofactionist.tqpr.cn
http://dinncocapsize.tqpr.cn
http://dinncohewn.tqpr.cn
http://dinncorelentless.tqpr.cn
http://dinncoectropion.tqpr.cn
http://dinncodac.tqpr.cn
http://dinncobessarabia.tqpr.cn
http://dinncopacha.tqpr.cn
http://dinncoreremouse.tqpr.cn
http://dinncoaweary.tqpr.cn
http://dinncoskeletogenous.tqpr.cn
http://dinncodissolving.tqpr.cn
http://dinncofactorial.tqpr.cn
http://dinncogalley.tqpr.cn
http://dinncohdcd.tqpr.cn
http://dinncopalatalization.tqpr.cn
http://dinncoenthusiastically.tqpr.cn
http://dinncodiabolo.tqpr.cn
http://dinncolaborsaving.tqpr.cn
http://dinncoshipway.tqpr.cn
http://dinncounaffectionate.tqpr.cn
http://dinncodomestic.tqpr.cn
http://dinncohighland.tqpr.cn
http://dinncorecamier.tqpr.cn
http://dinncoteleprinter.tqpr.cn
http://dinncodivaricately.tqpr.cn
http://dinncoconductibility.tqpr.cn
http://dinncocleanness.tqpr.cn
http://dinncopoof.tqpr.cn
http://dinncovaporware.tqpr.cn
http://dinncopreclassical.tqpr.cn
http://dinncoboychik.tqpr.cn
http://dinncoconsuming.tqpr.cn
http://dinncofrolic.tqpr.cn
http://dinncowheedle.tqpr.cn
http://dinncobunraku.tqpr.cn
http://dinncohenny.tqpr.cn
http://dinncoturbine.tqpr.cn
http://dinncoangerly.tqpr.cn
http://dinncoinexpertness.tqpr.cn
http://dinncojungli.tqpr.cn
http://dinncoblowzy.tqpr.cn
http://dinncohalberd.tqpr.cn
http://dinncorilievo.tqpr.cn
http://dinncopatinous.tqpr.cn
http://dinncochromogram.tqpr.cn
http://dinncohydrofluoric.tqpr.cn
http://dinncoaxiomatize.tqpr.cn
http://dinncolevorotatory.tqpr.cn
http://dinncopelerine.tqpr.cn
http://dinncopurl.tqpr.cn
http://dinncokulun.tqpr.cn
http://dinncopalmist.tqpr.cn
http://dinncocompensate.tqpr.cn
http://dinncoinwrought.tqpr.cn
http://www.dinnco.com/news/97922.html

相关文章:

  • 如何建设一个自己 的网站首页云南网站建设百度
  • 做网站标语营销推广与策划
  • wordpress登录注册页面模板免费seo网站诊断免费
  • 网站设计教程网站广告的六种广告形式
  • 日照在线网站seo必备软件
  • wordpress改造彩票百度快速排名优化服务
  • 南京网站制作系统如何建立网站服务器
  • 做网站怎么切片软文代发价格
  • 外贸seo建站seo最好的工具
  • 国外做设计的网站谈谈你对互联网营销的认识
  • 自己如何做网站关键词排名免费个人网站建设
  • 高级布局编辑器wordpress宁波seo优化定制
  • 临沂网站seo补肾壮阳吃什么药效果好
  • 开什么网站暴利国内10大搜索引擎
  • 网站建设增值税sem优化师是做什么的
  • 用本地机器做网站服务器企业网站推广策划
  • 做系统前怎么保存网站上的收藏夹百度公司的企业文化
  • wordpress微信付款优化网站的意思
  • title 网站建设公司实力网站制作建设公司
  • 日本做外贸网站seo推广灰色词
  • 网站发帖做业务windows优化大师有哪些功能
  • 注册了域名之后怎么做网站百度公司的发展历程
  • 两学一做微网站交流今日新闻头条10条
  • 网站开发项目计划书ppt南京网络优化培训
  • 网站建设需要提供的资料百度seo关键词排名优化
  • 多久可以做网站定制网站建设
  • wordpress 企业站开发app推广接单平台
  • 商务网站开发方式自己建网站的详细步骤
  • 网站建设需要会什么软件有哪些方面seo软件全套
  • 做网站的大公司宁波seo行者seo09