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

蓝桥杯备赛3.11

搜索

B3622 枚举子集(递归实现指数型枚举) - 洛谷

#include <bits/stdc++.h> using namespace std; int n; string path; void dfs(int pos) { if(pos > n) { //path 就存着前n个人的决策 cout << path << endl; return; } //不选 path += 'N'; dfs(pos + 1); path.pop_back();//回溯 清空现场 //选 path += 'Y'; dfs(pos + 1); path.pop_back();//清空现场 } int main() { cin >> n; dfs(1); return 0; }

P10448 组合型枚举 - 洛谷

#include <bits/stdc++.h> using namespace std; const int N = 1e3; int n,m; vector<int> path; void dfs(int begin) { if(path.size()==m) { for(auto &x:path) { cout << x << " "; } cout << endl; return ; } for(int i = begin;i <= n;++i) { path.push_back(i); dfs(i + 1); path.pop_back(); } } int main() { cin >> n >> m; dfs(1); return 0; }

B3623 枚举排列(递归实现排列型枚举) - 洛谷

#include <bits/stdc++.h> using namespace std; const int N = 1e3; int n,k; vector<int> path; bool st[15]; void dfs() { if(path.size()==k) { for(auto &x:path) { cout << x <<" "; } cout << endl; return; } for(int i = 1;i <= n;++i) { if(!st[i]) { path.push_back(i); st[i] = true; dfs(); st[i] = false; path.pop_back(); } } } int main() { cin >> n >> k; dfs(); return 0; }

P1706 全排列问题 - 洛谷

#include <bits/stdc++.h> using namespace std; const int N = 10; int n; vector<int> path; bool st[N]; void dfs() { if(path.size()== n) { for(auto &x:path) { printf("%5d",x); } cout << endl; return; } for(int i = 1;i <= n;++i) { if(!st[i]) { path.push_back(i); st[i] = true; dfs(); st[i] = false; path.pop_back(); } } } int main() { cin >> n; dfs(); return 0; }

P1036 [NOIP 2002 普及组] 选数 - 洛谷

#include <bits/stdc++.h> using namespace std; const int N = 25; int n,k; int ret; int path; int a[N]; bool isPrime(int x) { if(x < 2) return false; if(x == 2) return true; for(int i = 2;i <= x/i;++i) { if(x%i==0) return false; } return true; } void dfs(int pos,int begin) { if(pos > k) { if(isPrime(path)) ret++; return; } for(int i = begin;i <= n;++i) { path +=a[i]; dfs(pos + 1,i + 1); path -=a[i]; } } int main() { cin >> n >> k; for(int i = 1;i <= n;++i) { cin >> a[i]; } dfs(1,1); cout << ret; return 0; }

P9241 [蓝桥杯 2023 省 B] 飞机降落 - 洛谷

#include <bits/stdc++.h> using namespace std; const int N = 15; int t[N],d[N],l[N]; int T; int n; bool st[N]; bool dfs(int pos,int end) { if(pos > n) { return true; } for(int i = 1;i <= n;++i) { if(st[i]==true) continue; if(end > t[i] + d[i]) continue; int newend = max(end,t[i]) + l[i]; st[i] = true; if(dfs(pos + 1,newend)) return true; st[i] = false; } return false; } int main() { cin >> T; while(T--) { memset(st,false,sizeof st); cin >> n; for(int i = 1;i <= n;++i) { cin >> t[i] >> d[i] >> l[i]; } if(dfs(1,0)) cout <<"YES" << endl; else cout << "NO" << endl; } return 0; }
http://www.jsqmd.com/news/468610/

相关文章:

  • 通达信【超准主力专用抄底】副图与选股指标CJM99分享
  • linux学习笔记(yum命令)
  • 2026爆款外呼系统盘点|中小企业首选,高性价比闭眼入
  • swift-最新面试题二
  • 初级运维-基础命令
  • turtle学习
  • 这篇够全了:一线地理教学常用 GIS 工具与地图资源汇总
  • 医疗AI伦理漏洞全链路测试报告
  • 比亚迪闪充:不伤电池,不伤电网
  • mcs51单片机02
  • Asp.net core使用ayui表单Ajax提交请求,后台接收参数为空,模型绑定失败
  • ooderAgent 深度实战——给你的应用挂上懂程序的 AI Chat小助手
  • 福州Q235B螺旋钢管:城市建设的坚实脊梁
  • OpenClaw 版本更新 2026.3.8 不只是多了几个命令
  • iTOP-3588烧写ubuntu一文通完全手册
  • 亲密关系继续学习1
  • 标题五个字
  • 基于MATLAB/Simulink的60W反激变换器模型:Flyback模型,闭环控制,带sn...
  • 结构化分析结果与可视化图表
  • Simulink二次调频AGC风电风机储能与电动汽车、水电火电对比研究及系统频率波形分析
  • 面向金融的深度学习(提前发布)(三)
  • ArcGIS水文分析、HEC-RAS模拟技术在洪水危险性及风险评估
  • 用直白语言讲透 Transformer
  • 虚拟机部署fdbus
  • 氯丁橡胶与再生胶并用生产微波吸收材料
  • 权威榜单今年最佳top海外用工服务,解决您的用人需求
  • 2026年广州机械网页设计,报价大揭秘!你敢看吗?
  • APM日志添加自定义数据
  • 哈哈哈哈哈哈哈哈哈哈哈哈
  • openclaw平替之nanobot 源码解析(三):Markdown 驱动的系统提示词