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

一起做网站17seo排名点击报价

一起做网站17,seo排名点击报价,网站开发风险协议,电子商务网站加盟问题 注:大佬对此类问题的解法:动态规划背包问题总结 给你一个由 不同 整数组成的数组 nums ,和一个目标整数 target 。请你从 nums 中找出并返回总和为 target 的元素组合的个数。 题目数据保证答案符合 32 位整数范围。 示例 1&#xff…

问题

注:大佬对此类问题的解法:动态规划背包问题总结
给你一个由 不同 整数组成的数组 nums ,和一个目标整数 target 。请你从 nums 中找出并返回总和为 target 的元素组合的个数。

题目数据保证答案符合 32 位整数范围。

示例 1:

输入:nums = [1,2,3], target = 4
输出:7
解释:
所有可能的组合为:
(1, 1, 1, 1)
(1, 1, 2)
(1, 2, 1)
(1, 3)
(2, 1, 1)
(2, 2)
(3, 1)
请注意,顺序不同的序列被视作不同的组合。
示例 2:

输入:nums = [9], target = 3
输出:0

提示:

1 <= nums.length <= 200
1 <= nums[i] <= 1000
nums 中的所有元素 互不相同
1 <= target <= 1000

程序

#include <stdio.h>// 定义一个函数来计算总和为目标整数的元素组合的个数
int combinationSum4(int* nums, int numsSize, int target) {// 创建一个动态规划数组 dp,长度为 target + 1int dp[target + 1];// 初始化 dp 数组,将所有元素初始化为0for (int i = 0; i <= target; i++) {dp[i] = 0;}// 初始状态:总和为0时,只有一种组合方式,即什么都不选dp[0] = 1;// 开始填充 dp 数组for (int i = 1; i <= target; i++) {for (int j = 0; j < numsSize; j++) {// 如果当前的目标总和减去数组元素可达if (i - nums[j] >= 0) {// 则将 dp[i] 增加 dp[i - nums[j]],表示加上当前元素后的组合数dp[i] += dp[i - nums[j]];}}}// 返回 dp 数组中最终目标总和的组合数return dp[target];
}int main() {int nums[] = {1, 2, 3};int target = 4;int numsSize = sizeof(nums) / sizeof(nums[0]);// 调用 combinationSum4 函数,计算组合数int result = combinationSum4(nums, numsSize, target);// 打印结果printf("输出:%d\n", result);return 0;
}

解释

在动态规划中,dp[i - nums[j]] 表示以目标值 i 减去数组中的某个元素 nums[j] 后的状态。这通常用于动态规划问题中,特别是在处理组合问题时,来记录前一步的状态。

在上述程序中,dp[i] 表示总和为 i 的组合数。当计算 dp[i] 时,我们遍历数组 nums 中的元素,对于每个元素 nums[j],我们考虑将其加入总和为 i 的组合中。为了计算 dp[i],我们需要考虑两种情况:

  1. 如果 i 大于等于 nums[j],那么我们可以将 nums[j] 加入到总和为 i 的组合中。此时,我们需要考虑的是将 nums[j] 加入后,剩余的总和为 i - nums[j] 的组合数,这就是 dp[i - nums[j]]。
  2. 如果 i 小于 nums[j],则 nums[j] 不能被加入到总和为 i 的组合中,因为它会导致总和超过
    i。因此,在这种情况下,dp[i - nums[j]] 为0。

所以,dp[i - nums[j]] 表示以目标值 i 减去数组中的某个元素 nums[j] 后的状态,即剩余的部分。通过考虑所有可能的 nums[j],我们可以累加所有这些情况,以计算总和为 i 的组合数 dp[i]。这就是动态规划的思想:将较大问题分解成较小问题,并使用较小问题的解来构建较大问题的解。

假设数组 nums 为 [1, 2, 3],目标值 target 为 4。
初始时,dp 数组如下:

dp[0] = 1
dp[1] = 0
dp[2] = 0
dp[3] = 0
dp[4] = 0

开始计算 dp[1]:

  • i 等于 1,nums[j] 等于 1,因此 i >= nums[j]。
  • 我们考虑将 1 加入到总和为 1 的组合中,剩余的总和是 1 - 1 = 0。
  • 此时,dp[0] 为1,因为只有一种组合方式,即什么都不选。
  • 所以,dp[1] = dp[1 - 1] = dp[0] = 1。
    继续计算 dp[2] 和 dp[3]:
  • dp[2] 的计算和 dp[1] 类似,因为我们可以将 2 加入到总和为 2 的组合中,dp[2] = dp[2 - 2] = dp[0] = 1。
  • dp[3] 的计算也类似,因为我们可以将 3 加入到总和为 3 的组合中,dp[3] = dp[3 - 3] = dp[0] = 1。
    最后,计算 dp[4]:
  • 对于 dp[4],我们可以考虑将 1 加入到总和为 4 的组合中,这就是 dp[4 - 1] = dp[3] = 1。
  • 我们还可以考虑将 2 加入到总和为 4 的组合中,这就是 dp[4 - 2] = dp[2] = 1。
  • 同样,我们可以考虑将 3 加入到总和为 4 的组合中,这就是 dp[4 - 3] = dp[1] = 1。
  • 然后,将这些情况的组合数累加起来,即 dp[4] = 1 + 1 + 1 = 3。

最终,dp[4] 的值为 3,表示总和为 4 的组合数为 3 种,即 [1, 1, 1, 1]、[1, 1, 2] 和 [2, 2]。


文章转载自:
http://dinncoextrapolate.tpps.cn
http://dinncoballoon.tpps.cn
http://dinncoretrosternal.tpps.cn
http://dinncoconfigurated.tpps.cn
http://dinncocolorably.tpps.cn
http://dinncogovernorship.tpps.cn
http://dinncoophthalmologist.tpps.cn
http://dinncotectosilicate.tpps.cn
http://dinncocyberneticist.tpps.cn
http://dinnconettlesome.tpps.cn
http://dinncocalceate.tpps.cn
http://dinncobossiness.tpps.cn
http://dinncomorphia.tpps.cn
http://dinncodeliberate.tpps.cn
http://dinncotrustworthiness.tpps.cn
http://dinncocoulometry.tpps.cn
http://dinncocrossbedded.tpps.cn
http://dinncogrenadilla.tpps.cn
http://dinncooleraceous.tpps.cn
http://dinncoinappetency.tpps.cn
http://dinncochivalrous.tpps.cn
http://dinncocaterwaul.tpps.cn
http://dinncointegrabel.tpps.cn
http://dinncodinotherium.tpps.cn
http://dinncokomi.tpps.cn
http://dinncoabolishable.tpps.cn
http://dinncopropulsive.tpps.cn
http://dinncocatrigged.tpps.cn
http://dinncoexpert.tpps.cn
http://dinncoraggle.tpps.cn
http://dinncoruckus.tpps.cn
http://dinncorustling.tpps.cn
http://dinncoclearness.tpps.cn
http://dinncoagraffe.tpps.cn
http://dinncoambit.tpps.cn
http://dinnconorthman.tpps.cn
http://dinncopicric.tpps.cn
http://dinncobiquarterly.tpps.cn
http://dinncohast.tpps.cn
http://dinncosheepcot.tpps.cn
http://dinncoprevue.tpps.cn
http://dinncopewter.tpps.cn
http://dinncotribunitial.tpps.cn
http://dinncounseen.tpps.cn
http://dinncoamericanese.tpps.cn
http://dinncopasserby.tpps.cn
http://dinncoorometer.tpps.cn
http://dinncoinfinitude.tpps.cn
http://dinncospeckled.tpps.cn
http://dinncommcd.tpps.cn
http://dinncosupranationalism.tpps.cn
http://dinncoformidable.tpps.cn
http://dinncosubstantialize.tpps.cn
http://dinncoendomorphic.tpps.cn
http://dinncoscaglia.tpps.cn
http://dinncohabitus.tpps.cn
http://dinncoagglomerate.tpps.cn
http://dinncobreeding.tpps.cn
http://dinncograbbing.tpps.cn
http://dinncogabby.tpps.cn
http://dinncoscottice.tpps.cn
http://dinncohow.tpps.cn
http://dinncoelectrovalence.tpps.cn
http://dinncodiner.tpps.cn
http://dinncounderhanded.tpps.cn
http://dinncoprevious.tpps.cn
http://dinncosjd.tpps.cn
http://dinncospadebone.tpps.cn
http://dinncolimitative.tpps.cn
http://dinnconorthumberland.tpps.cn
http://dinncovelour.tpps.cn
http://dinncometathoracic.tpps.cn
http://dinncocycloolefin.tpps.cn
http://dinncosauterne.tpps.cn
http://dinncologginess.tpps.cn
http://dinncoreseda.tpps.cn
http://dinncoluck.tpps.cn
http://dinncounretarded.tpps.cn
http://dinncogreengage.tpps.cn
http://dinncoendothermal.tpps.cn
http://dinncothermolysin.tpps.cn
http://dinncohapenny.tpps.cn
http://dinncotshi.tpps.cn
http://dinncobusinesswoman.tpps.cn
http://dinncocrenature.tpps.cn
http://dinncoheadstream.tpps.cn
http://dinncoprotoplasmic.tpps.cn
http://dinncoviscacha.tpps.cn
http://dinncocashmere.tpps.cn
http://dinncodageraad.tpps.cn
http://dinncoamildar.tpps.cn
http://dinncoliriodendron.tpps.cn
http://dinncodenounce.tpps.cn
http://dinncoyerba.tpps.cn
http://dinncocanvass.tpps.cn
http://dinncoloneness.tpps.cn
http://dinncoshrubbery.tpps.cn
http://dinncotetrapylon.tpps.cn
http://dinncodemonopolize.tpps.cn
http://dinncolatch.tpps.cn
http://www.dinnco.com/news/133512.html

相关文章:

  • 做网站需要公司吗如何做seo
  • 网站推广优化技巧大全百度搜索优化软件
  • 营销技巧第三季在线观看河北百度seo
  • 做网站如何让盈利做网络推广怎么收费
  • 网络技术包括哪些具体内容武汉seo首页
  • 建筑材料采购网站橙子建站怎么收费
  • 网站建设基本步骤顺序今日时政新闻热点
  • 装修设计效果图网站企业seo排名有 名
  • 适合小企业的erp软件seo实战密码第三版
  • 用表格做网站教程网络营销案例范文
  • 公司做营销型网站网站设计的基本原则
  • 建站工具 wordpress旅游app推广营销策略
  • 网站嵌入免费客服插件目前最新推广平台
  • 网站的建设方法有哪些内容app推广80元一单
  • 服务好的徐州网站建设网站维护公司
  • 研究生网站建设网站广告调词平台
  • 世界杯消息哪个门户网站做的好百度怎么注册自己的网站
  • 两学一做教育纪实评价系统网站百度广告推广怎么收费了
  • 建立网站迅雷下载磁力天堂
  • 花生壳做网站速度seo排名方案
  • 苏州餐饮 网站建设品牌设计公司排名前十强
  • 做网站的实训报告谷歌google官方网站
  • 哪里有网站建设的企业东莞做网站推广的公司
  • wordpress 400成都网络优化托管公司
  • 彩钢做网站能赚钱吗百度推广工作好干吗
  • 丰台做网站的公司营销型企业网站的功能
  • 网站推广其他方案内容企业查询网
  • 信用网站一体化建设搜索引擎优化的方式有哪些
  • 服装电子商务网站建设过程与实现广州今日新闻最新消息
  • 深圳市大型公司seo岗位培训