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

如何创办网站旅游景点推广软文

如何创办网站,旅游景点推广软文,做网站商标分类,网站开发文档源码1.暴力递归 &#xff08;1&#xff09;剩余金额小于0&#xff0c;无解 剩余金额等于0&#xff0c;有解 剩余金额大于0&#xff0c;继续递归 &#xff08;2&#xff09;从大的硬币到小的硬币&#xff0c;可以减少循环次数 #include <bits/stdc.h> using namespace std;…

 1.暴力递归

(1)剩余金额小于0,无解

        剩余金额等于0,有解

        剩余金额大于0,继续递归

(2)从大的硬币到小的硬币,可以减少循环次数

#include <bits/stdc++.h>
using namespace std;int amount;
int coins[10]={5,2,1};
int res(int index,int* coins,int remainder)
{
//    剩余金额小于0,无解if(remainder<0){return 0;}
//    剩余金额等于0,有解else if(remainder==0){return 1;}
//    剩余金额大于0,继续递归else{int mycount=0;for(int i=index; i<3; i++){mycount+=res(i,coins,remainder-coins[i]);}return mycount;}}int main()
{amount=5;cout<<res(0,coins,amount);
}

如果要输出方案的话要用栈,让gpt写一下

#include <iostream>
#include <stack>
using namespace std;int amount;
int coins[10] = {1, 2, 5};void printCombination(stack<int>& combination) {stack<int> tempStack;while (!combination.empty()) {tempStack.push(combination.top());combination.pop();}cout << "Combination: ";while (!tempStack.empty()) {cout << tempStack.top() << " ";combination.push(tempStack.top());tempStack.pop();}cout << endl;
}int res(int index, int* coinList, int remainder, stack<int>& combination) {if (remainder < 0) {return 0;} else if (remainder == 0) {printCombination(combination);return 1;} else {int mycount = 0;for (int i = index; i < 3; i++) {combination.push(coins[i]);mycount += res(i, coinList, remainder - coins[i], combination);combination.pop();}return mycount;}
}int main() {amount = 5;stack<int> combination;cout << "Total combinations: " << res(0, coins, amount, combination) << endl;return 0;
}

http://www.hkea.cn/news/51619/

相关文章:

  • 郑州做网站好的公搜索引擎优化好做吗
  • 网站 预算白度
  • 中国电商建站程序信息推广
  • 网站开发教程 布局优化技术
  • 做外贸网站需要请外贸文员吗网站seo诊断分析和优化方案
  • 百度网站怎么做的赚钱吗seo中文含义
  • 做网站界面的软件互联网培训
  • 电子商务网站建设与维护李建忠高级搜索引擎技巧
  • 做地产网站全网搜索软件
  • 网站开发培训班百度网站推广关键词怎么查
  • 东莞市做网站公司seo怎样
  • ps做网站大小尺寸应用商店优化
  • 网站站群建设方案知名网页设计公司
  • 广州网站建设公司哪家好专业的seo搜索引擎优化培训
  • 外国人做汉字网站seo搜索排名影响因素主要有
  • 外贸五金网站建设网站制作优化排名
  • 义乌网站建设多少钱网络平台营销
  • 怀仁有做网站的公司吗磁力搜索引擎2023
  • 建站行业都扁平化设计合肥网站推广公司哪家好
  • 做企业网站织梦和wordpress哪个好百度指数查询工具app
  • 郑州网站服务公司优化神马排名软件
  • 茶叶网站建设的优势南宁seo外包平台
  • 高古楼网站 做窗子北京seo技术交流
  • 南阳建设网站制作网络最有效的推广方法
  • 纯静态网站seoseo排名优化北京
  • 开封网站建设哪家好指数计算器
  • 网站开发 架构石家庄seo关键词排名
  • 可以免费做商业网站的cms百度seo霸屏软件
  • 哪家网站建设专业快速建站教程
  • 坪山网站建设行业现状优化seo方案