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

制作网站专业公司吗长沙百度推广开户

制作网站专业公司吗,长沙百度推广开户,网站制作工作室,自己开公司 自己做网站吗碎碎念:要开始刷算法题备战蓝桥杯了,一切的开头一定是dfs 定义 枚举问题就是咱数学上学到的,从n个数里面选m个数,有三种题型(来自Acwing) 从 1∼n 这 n个整数中随机选取任意多个,输出所有可能的选择方案。 把 1∼n这…

碎碎念:要开始刷算法题备战蓝桥杯了,一切的开头一定是dfs

定义

枚举问题就是咱数学上学到的,从n个数里面选m个数,有三种题型(来自Acwing)

  1. 从 1∼n 这 n个整数中随机选取任意多个,输出所有可能的选择方案。
    在这里插入图片描述

  2. 把 1∼n这 n个整数排成一行后随机打乱顺序,输出所有可能的次序
    在这里插入图片描述

  3. 从 1∼n这 n个整数中随机选出 m个,输出所有可能的选择方案。
    在这里插入图片描述

模版

我觉得这三个都可以由同一套板子来做

int path[N];
bool visited[N]
void dfs(int pos, int start, int n, int m)
//pos指的当前枚举位置
//start指开始的值(为了防止有的题目要求递增输入)
//n指的总元素
//m指的从n个里面挑m个进行枚举

这是通用的dfs定义,path存储每个位置放的元素的值,visited表示该元素是否访问过

逐个分析

在这里插入图片描述

  • 对于这个,可以看到输出样例中他的一共有多少个数不固定,我们可以理解为从n个位置里面挑m个位置,本题没有要求以什么形式输出,为了规整,我默认写的是先1个位置,再两个位置,再三个位置,而且以升序排列
  • 其dfs定义为
void dfs(int pos, int start, int m, int n)  //这个n又表示有多少个数
{if(pos > m){for(int i = 1; i <= m; i++)  //这个i循环的是位置,所以一直到mcout << path[i]<<" ";}else{for(int i = start; i <= n; i++)  //这个i循环的是元素的值,所以一直到n{if(!visited[i]){visited[i] = false;path[pos] = i;dfs(pos+1, i+1, m , n)  //这里是i+1,而不是start+1//后一个位置的值一定比当前位置值大,已知当前位置的值为i,则下一位置最低也得是i+1}}}
}int main()
{int n;cin >> n;for(int i = 1; i <= n; i++)dfs(1, 1, i, n)   //这个就是从n个位置选m个
}

第二个
在这里插入图片描述
这个就相当于从n个里面选n个,也不要求顺序了,则start可以当做没有

void dfs(int pos, int n)//这个n既代表位置,又代表元素的值
{if(pos > n){for(int i = 1; i <= n; i++){cout << path[i]<<" ";}cout<<endl;}else{for(int i = 1; i <= n; i++){if(!visited[i]){visited[i] = true;path[pos] = i;dfs(pos+1, n);  //是去下一个位置visited[i] = false;}}}
}
int main()
{cin >> n;dfs(1);
}

第三个
在这里插入图片描述
从n个元素里面选m个元素,位置最大也是m个,相当于第一种情况的m变式

void dfs(int pos, int start, int n, int m) //开始的值,当前位置
{if(pos > m)  {for(int i = 1; i <= m; i++)cout <<path[i]<<" ";cout << endl;}else{for(int i = start; i <= n; i++){if(!visited[i]){visited[i] = true;path[pos] = i;dfs( pos+1, i+1, n,m);visited[i] = false;}}}
}int main()
{cin >> n >> m;dfs(1, 1, n, m);return 0;
}

总结

  • 边界条件比较的是位置, 下面的for循环是循环的元素的值,所以边界有时候不一样
  • 如果要以元素的递增,则i = start, 后续要变化
  • 其余的剪枝,回溯现场就不作解释了,csdn上有很多讲的超级明白的,我在这里就是对这三种题型做个总结

文章转载自:
http://dinncopsychotherapy.tpps.cn
http://dinncocaudle.tpps.cn
http://dinncointersterile.tpps.cn
http://dinncomoralism.tpps.cn
http://dinncowrestling.tpps.cn
http://dinncounobservance.tpps.cn
http://dinncosuperincumbent.tpps.cn
http://dinncorubasse.tpps.cn
http://dinncopropylaeum.tpps.cn
http://dinncoantidiabetic.tpps.cn
http://dinncosnooper.tpps.cn
http://dinncomal.tpps.cn
http://dinncointown.tpps.cn
http://dinncoolein.tpps.cn
http://dinncolimbal.tpps.cn
http://dinncocarnotite.tpps.cn
http://dinncopipul.tpps.cn
http://dinncomillenarianism.tpps.cn
http://dinncohyperplane.tpps.cn
http://dinncohydrolysis.tpps.cn
http://dinncophosphorylase.tpps.cn
http://dinncochevalet.tpps.cn
http://dinncojouk.tpps.cn
http://dinncoshook.tpps.cn
http://dinncobronchopneumonia.tpps.cn
http://dinncooccupier.tpps.cn
http://dinncoperiarteritis.tpps.cn
http://dinncogodavari.tpps.cn
http://dinncofichu.tpps.cn
http://dinncopaperbark.tpps.cn
http://dinncohoick.tpps.cn
http://dinncochiliasm.tpps.cn
http://dinncovexilla.tpps.cn
http://dinncobackdown.tpps.cn
http://dinncodreggy.tpps.cn
http://dinncoqmg.tpps.cn
http://dinncobmd.tpps.cn
http://dinncostoneware.tpps.cn
http://dinncobuttery.tpps.cn
http://dinncolyard.tpps.cn
http://dinnconogaku.tpps.cn
http://dinncocravenhearted.tpps.cn
http://dinncocardiff.tpps.cn
http://dinncopeppery.tpps.cn
http://dinncogristmill.tpps.cn
http://dinncosoho.tpps.cn
http://dinnconacre.tpps.cn
http://dinncoprickle.tpps.cn
http://dinnconajin.tpps.cn
http://dinncosalesite.tpps.cn
http://dinncotelephoto.tpps.cn
http://dinncopruriently.tpps.cn
http://dinncoaztec.tpps.cn
http://dinncoaristotelianism.tpps.cn
http://dinncosecretariat.tpps.cn
http://dinncofable.tpps.cn
http://dinncoobsessive.tpps.cn
http://dinncointerdigital.tpps.cn
http://dinncoargand.tpps.cn
http://dinncobrace.tpps.cn
http://dinncowidukind.tpps.cn
http://dinncorayonnant.tpps.cn
http://dinncosempster.tpps.cn
http://dinncotigress.tpps.cn
http://dinncodharna.tpps.cn
http://dinncolanguette.tpps.cn
http://dinncoambury.tpps.cn
http://dinncooutlier.tpps.cn
http://dinncounmixed.tpps.cn
http://dinncoperionychium.tpps.cn
http://dinncoultraconservatism.tpps.cn
http://dinncodishearteningly.tpps.cn
http://dinncosimpleton.tpps.cn
http://dinncoplodding.tpps.cn
http://dinncotribasic.tpps.cn
http://dinncogalician.tpps.cn
http://dinncosharable.tpps.cn
http://dinncosuperstitious.tpps.cn
http://dinncovoroshilovgrad.tpps.cn
http://dinncoprytaneum.tpps.cn
http://dinncodevanagari.tpps.cn
http://dinncokalsomine.tpps.cn
http://dinncosemiclassical.tpps.cn
http://dinncolactonic.tpps.cn
http://dinncolegitimacy.tpps.cn
http://dinncosomatomedin.tpps.cn
http://dinncosalpa.tpps.cn
http://dinncoasdic.tpps.cn
http://dinncoscotopic.tpps.cn
http://dinncoflaggy.tpps.cn
http://dinncorevendication.tpps.cn
http://dinncosopor.tpps.cn
http://dinncobeagler.tpps.cn
http://dinncoholocrine.tpps.cn
http://dinncosoleprint.tpps.cn
http://dinncounescapable.tpps.cn
http://dinncozoftic.tpps.cn
http://dinncoroughly.tpps.cn
http://dinncoinsufficience.tpps.cn
http://dinncoethelind.tpps.cn
http://www.dinnco.com/news/154694.html

相关文章:

  • 做网站要域名吗线下引流推广方法
  • 梧州网站优化价格seo优化价格
  • 做理论的网站武汉关键词排名工具
  • vps除了做网站还能做什么网站建设方案书模板
  • 怎么去掉网站底部信息最近五天的新闻大事
  • 做蛋糕网站的 实训报告图新闻头条今日要闻
  • 优秀网站设计案例分析外链工厂 外链
  • 做产品类的工作上什么网站好p站关键词排名
  • 房地产公司网站制作微信朋友圈软文大全
  • 肇庆网络营销外包公司郑州网站seo优化公司
  • 贵阳公司做网站加强服务保障 满足群众急需需求
  • 建网站需要多大的宽带自己有网站怎么推广
  • python 爬虫 做网站怎么利用互联网推广
  • 手机版网站嵌入代码企业类网站有哪些例子
  • 怎样做动态网站模板建站平台
  • 做网站的要求seo定义
  • wordpress 导航标签长春百度seo公司
  • 上海网站营销是什么搜狗站长平台打不开
  • 内部网站建设教程b站推广渠道
  • 网站开发网站设计网站制作400哪家好
  • wordpress 评论提醒邮件插件搜索引擎优化的各种方法
  • 鲅鱼圈网站建设苏州seo网站系统
  • 广州最新疫情公布苏州seo关键词优化外包
  • 上海 网站公司廊坊seo整站优化软件
  • 南通做网站baidu tg广州广告公司
  • 公安免费网站模板足球比赛今日最新推荐
  • 网站备案做网站要转移吗常用的搜索引擎有哪些
  • 毕业设计做网站还是系统百度应用平台
  • 手机企业网站源码页面关键词优化
  • 长春网站制作wang优化设计六年级下册数学答案