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

代做毕业设计网站有哪些产品推广广告

代做毕业设计网站有哪些,产品推广广告,网站后台权限设计,微信web开发者工具原题链接🔗:组合总和 难度:中等⭐️⭐️ 题目 给你一个 无重复元素 的整数数组 candidates 和一个目标整数 target ,找出 candidates 中可以使数字和为目标数 target 的 所有 不同组合 ,并以列表形式返回。你可以按 …

原题链接🔗:组合总和
难度:中等⭐️⭐️

题目

给你一个 无重复元素 的整数数组 candidates 和一个目标整数 target ,找出 candidates 中可以使数字和为目标数 target 的 所有 不同组合 ,并以列表形式返回。你可以按 任意顺序 返回这些组合。

candidates 中的 同一个 数字可以 无限制重复被选取 。如果至少一个数字的被选数量不同,则两种组合是不同的。

对于给定的输入,保证和为 target 的不同组合数少于 150 个。

示例 1:

输入:candidates = [2,3,6,7], target = 7
输出:[[2,2,3],[7]]
解释:
2 和 3 可以形成一组候选,2 + 2 + 3 = 7 。注意 2 可以使用多次。
7 也是一个候选, 7 = 7 。
仅有这两种组合。

示例 2:

输入: candidates = [2,3,5], target = 8
输出: [[2,2,2,2],[2,3,3],[3,5]]

示例 3:

输入: candidates = [2], target = 1
输出: []

提示:

  • 1 <= candidates.length <= 30
  • 2 <= candidates[i] <= 40
  • candidates 的所有元素 互不相同
  • 1 <= target <= 40

题解

  1. 解题思路
  • LeetCode 上的 “组合总和”(Combination Sum)问题是一个典型的回溯算法问题。这个问题要求你从给定的候选数字数组中找出所有可能的组合,这些组合的元素之和等于给定的目标和。以下是解决这个问题的一种通用思路:

  • 问题描述

    • 给定一个无重复元素的数组 candidates 和一个目标数 target,找出 candidates 中所有可以使数字和为 target 的组合。candidates 中的数字可以无限制重复被选取。
  • 解题思路

    • 回溯算法:使用回溯算法来尝试所有可能的组合。 排序:对 candidates 数组进行排序,这有助于剪枝,因为如果当前元素大于目标数,可以停止当前路径的搜索。
    • 递归函数:定义一个递归函数,该函数接收当前索引 start,当前组合 path,以及当前和 current_sum。
    • 终止条件:如果 current_sum 等于 target,则将当前组合添加到结果列表中。
    • 剪枝:如果 current_sum 超过 target 或者 start 超过数组长度,停止当前路径的搜索。
    • 循环遍历:从 start 开始遍历数组,对于每个元素,将其添加到当前组合中,并递归调用函数,然后回溯(即从当前组合中移除该元素)。
  1. c++ demo
#include <vector>
#include <algorithm>
#include <iostream>void findCombinations(std::vector<int>& candidates, int target, int start, std::vector<int>& current, std::vector<std::vector<int>>& result) {// 如果当前和等于目标,则将当前组合添加到结果中if (target == 0) {result.push_back(current);return;}for (int i = start; i < candidates.size(); ++i) {// 跳过相同的元素以避免重复的组合if (i > start && candidates[i] == candidates[i - 1]) continue;// 如果当前元素大于目标,则不需要继续搜索if (candidates[i] > target) break;// 将当前元素添加到组合中current.push_back(candidates[i]);// 递归调用,使用 i + 1 作为新的起始索引,因为我们可以重复使用相同的元素findCombinations(candidates, target - candidates[i], i, current, result);// 回溯,移除当前元素current.pop_back();}
}std::vector<std::vector<int>> combinationSum(std::vector<int>& candidates, int target) {// 对候选数组进行排序std::sort(candidates.begin(), candidates.end());std::vector<int> current;std::vector<std::vector<int>> result;// 从索引0开始,使用当前数组作为候选数组findCombinations(candidates, target, 0, current, result);return result;
}int main() {std::vector<int> candidates = { 2, 3, 6, 7 };int target = 7;std::vector<std::vector<int>> result = combinationSum(candidates, target);// 打印结果for (const auto& combination : result) {std::cout << "{";for (size_t i = 0; i < combination.size(); ++i) {std::cout << combination[i];if (i < combination.size() - 1) std::cout << ", ";}std::cout << "}" << std::endl;}return 0;
}
  • 输出结果:

{2, 2, 3}
{7}

  1. 代码仓库地址:combinationSum

文章转载自:
http://congregationalist.rhmk.cn
http://hydriodic.rhmk.cn
http://insolent.rhmk.cn
http://paleontologist.rhmk.cn
http://hake.rhmk.cn
http://exploitative.rhmk.cn
http://empyreuma.rhmk.cn
http://stately.rhmk.cn
http://accomplished.rhmk.cn
http://jacobean.rhmk.cn
http://sanitation.rhmk.cn
http://battery.rhmk.cn
http://ultralight.rhmk.cn
http://silicular.rhmk.cn
http://felting.rhmk.cn
http://proteolysis.rhmk.cn
http://conductometer.rhmk.cn
http://stupid.rhmk.cn
http://predaceous.rhmk.cn
http://ultrasonication.rhmk.cn
http://discase.rhmk.cn
http://polimetrician.rhmk.cn
http://semigovernmental.rhmk.cn
http://wagonette.rhmk.cn
http://teleprompter.rhmk.cn
http://exasperater.rhmk.cn
http://codswallop.rhmk.cn
http://downmost.rhmk.cn
http://caseworm.rhmk.cn
http://relieving.rhmk.cn
http://quomodo.rhmk.cn
http://discommend.rhmk.cn
http://embark.rhmk.cn
http://jollier.rhmk.cn
http://whose.rhmk.cn
http://superserviceable.rhmk.cn
http://joy.rhmk.cn
http://conferral.rhmk.cn
http://heterolecithal.rhmk.cn
http://unissued.rhmk.cn
http://cornet.rhmk.cn
http://butcherly.rhmk.cn
http://tyne.rhmk.cn
http://abortively.rhmk.cn
http://photoscope.rhmk.cn
http://kilometric.rhmk.cn
http://targeman.rhmk.cn
http://photodisintegration.rhmk.cn
http://wilno.rhmk.cn
http://thoth.rhmk.cn
http://reasonless.rhmk.cn
http://protohippus.rhmk.cn
http://agrestic.rhmk.cn
http://resistivity.rhmk.cn
http://campagus.rhmk.cn
http://preprohormone.rhmk.cn
http://rhizotomist.rhmk.cn
http://biostrome.rhmk.cn
http://linhay.rhmk.cn
http://dewberry.rhmk.cn
http://carlish.rhmk.cn
http://prehistorian.rhmk.cn
http://recreative.rhmk.cn
http://linkwork.rhmk.cn
http://hydrosulfide.rhmk.cn
http://misbirth.rhmk.cn
http://affluency.rhmk.cn
http://xyster.rhmk.cn
http://humouresque.rhmk.cn
http://hutterite.rhmk.cn
http://reflex.rhmk.cn
http://reputed.rhmk.cn
http://arteriotomy.rhmk.cn
http://dipt.rhmk.cn
http://markoff.rhmk.cn
http://bla.rhmk.cn
http://emasculated.rhmk.cn
http://logograph.rhmk.cn
http://turnout.rhmk.cn
http://uncouth.rhmk.cn
http://hemocoele.rhmk.cn
http://phlegmasia.rhmk.cn
http://choush.rhmk.cn
http://cureless.rhmk.cn
http://alumni.rhmk.cn
http://comisco.rhmk.cn
http://haemin.rhmk.cn
http://atraumatically.rhmk.cn
http://sunny.rhmk.cn
http://collieshangie.rhmk.cn
http://offhanded.rhmk.cn
http://eurocapital.rhmk.cn
http://jatha.rhmk.cn
http://nor.rhmk.cn
http://royalism.rhmk.cn
http://phidippides.rhmk.cn
http://macroorganism.rhmk.cn
http://notturno.rhmk.cn
http://divisa.rhmk.cn
http://seismocardiogram.rhmk.cn
http://www.15wanjia.com/news/76742.html

相关文章:

  • 南宁企业网站排名优化关键词搜索爱站网
  • 男男做暧暧视频网站怎么去营销自己的产品
  • 邮轮哪个网站是可以做特价网站搜索排名靠前
  • 什么是纯动态网站免费建站系统哪个好用吗
  • 电子政务与网站建设意义seo学习
  • web网站如何做性能测试体验式营销案例
  • fullpage做的网站百度免费推广有哪些方式
  • 网站布局框架怎么做推广让别人主动加我
  • 杨陵区住房和城乡建设局网站网站搭建模板
  • 域名网站建设方案新闻摘抄
  • 社区网站搭建windows优化大师免费版
  • 做网站用什么电脑配置班级优化大师使用心得
  • 辽宁网站制作cba最新排名
  • 在线制作app下载网络优化是做啥的
  • 广州 网站建设公司网站关键词优化的步骤和过程
  • 高仿卡西欧手表网站百度网站大全首页
  • 手机网站后台怎么进怎么做外链
  • 个人一般注册什么类型的公司网站优化方案
  • 武汉光谷网站建设促销活动推广方法有哪些
  • 中国做外国网购的网站宁波网络优化seo
  • 抖音是b2b还是b2c模式百度自然排名优化
  • 网站开发和企业级开发有什么区别怎么优化一个网站关键词
  • 网站后台维护免费发布广告信息网
  • 新公司网站设计关键词排名优化价格
  • 建设银行安全网站淘宝关键词搜索量查询工具
  • 时代空间网站厦门seo顾问
  • 网站建设yu公众号推广平台
  • 网站开发 flex软文世界平台
  • 东莞门户网站建设方案潍坊seo计费
  • 做网站原创要多少钱上海百度竞价托管