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

建设银行集团网站网站空间商排行榜

建设银行集团网站,网站空间商排行榜,网站托管如何收费,天津企业设计网站建设P1036 [NOIP 2002 普及组] 选数 - 洛谷 组合型枚举&#xff0c;路径⾥⾯记录选择数的「总和」。在选出k 个数之后&#xff0c;判断「是否是质数」 #include <bits/stdc.h> using namespace std;const int N 25; int n, k; int a[N];int ret; int path; //记录路径中所…
P1036 [NOIP 2002 普及组] 选数 - 洛谷

组合型枚举,路径⾥⾯记录选择数的「总和」。在选出k 个数之后,判断「是否是质数」

#include <bits/stdc++.h>
using namespace std;const int N = 25;
int n, k;
int a[N];int ret;
int path; //记录路径中所选择的数的和bool isprime(int x)
{if (x <= 1) return false;//试除法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()
{ios::sync_with_stdio(false);cin.tie(0);cin >> n >> k;for (int i = 1; i <= n; i++) cin >> a[i];dfs(1, 1);cout << ret << endl;return 0;
}
P9241 [蓝桥杯 2023 省 B] 飞机降落 - 洛谷

枚举所有⻜机的「全排列」,判断是否存在⼀种排列,使的全部的⻜机都能安全降落。
剪枝:

  • 当前路径⾥⾯只能选没有选过的⻜机;
  • 如果这架⻜机不能正常降落,剪掉;
  • 如果已经找到⼀种安全降落的⽅式,停⽌枚举,可以通过「递归的返回值」判断是否搜索成功
#include <bits/stdc++.h>
using namespace std;const int N = 15;int n;
int t[N], d[N], l[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(t[i], end) + l[i];st[i] = true;if (dfs(pos+1, newend)) return true;st[i] = false; //恢复现场}return false;
}int main()
{ios::sync_with_stdio(false);cin.tie(0);int T; cin >> T;while (T--){memset(st, 0, 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;
}
P1219 [USACO1.5] 八皇后 Checker Challenge - 洛谷

![[Pasted image 20250407101514.png]]

枚举策略:

  • 「⼀⾏⼀⾏」的放皇后:从第⼀⾏开始,尝试在每⼀列上放皇后;
  • 如果当前列放上皇后之后「没有冲突」,就标记⼀下这个「放法」,记录⼀下当前⾏的决策,然后「递归」考虑下⼀⾏;
  • 等到「所有⾏」都放置完毕之后,输出本次枚举的决策。
    枚举策略应该是⽐较容易想到的,这道题的难点在于如何判断「在这⼀列放上这个皇后之后,是否冲突」。当我们⼀⾏⼀⾏放的时候,「⾏是不会产⽣冲突的」。产⽣冲突的只有「列」,「主对⻆线」,以及「副对⻆线」。我们可以⽤三个数组分别标记:
  • col[i] = true ,表⽰第i ⾏放置了⼀个皇后;
  • dig1[j - i + n] = true,表⽰y = x + (j - i)这条「主对⻆线」上放置了⼀个皇后;
  • dig2[j + i] = true ,表⽰y = -x + (j + i)这条「副对⻆线」上放置了⼀个皇后
#include <bits/stdc++.h>
using namespace std;const int N = 15;int n;
bool col[N], st1[N*2], st2[N*2];int ret;
vector<int> path;void dfs(int x)
{if (x > n){ret++;if (ret <= 3){for (auto x : path) cout << x << " ";cout << endl;}return;}for (int y = 1; y <= n; y++){//判断能不能摆在这一列if (col[y] || st1[y-x+n] || st2[x+y]) continue; //剪枝col[y] = st1[y-x+n] = st2[x+y] = true;path.push_back(y);dfs(x+1);col[y] = st1[y-x+n] = st2[x+y] = false;path.pop_back();}
}int main()
{ios::sync_with_stdio(false);cin.tie(0);cin >> n;dfs(1);cout << ret << endl;return 0;
}
P1784 数独 - 洛谷

![[Pasted image 20250407104104.png]]

枚举策略:

  • 「⼀个格⼦⼀个格⼦」往⾥⾯填数
  • 从第⼀⾏的第⼀个格⼦开始,填上⼀个「没有冲突」的数,然后「递归」到下⼀个格⼦;
  • 当某⼀⾏填满之后,递归到「下⼀⾏的起始位置」继续填数。
    可以创建三个数组,⽤来帮助判断填上某⼀个数之后,是否会发⽣冲突。对于3x3⽅格,我们可以给每⼀个格⼦编上号,快读定位。
  • row[i][num] = true表⽰:第i ⾏已经放上了num 这个数;
  • col[j][num] = true表⽰:第j 列已经放上了num 这个数;
  • st[i/3][j/3][num] = true表⽰:[i/3, j/3]的3 × 3 ⽅格⾥,已经放上了num 这个数
#include <bits/stdc++.h>
using namespace std;int n = 9;
const int N = 10;
int a[N][N];
bool row[N][N], col[N][N], st[N][N][N];bool dfs(int i, int j)
{if (j == n){//填满一行后i++;j = 0;}if (i == n) return true;if (a[i][j]) return dfs(i, j+1);for (int x = 1; x <= 9; x++){if (row[i][x] || col[j][x] || st[i/3][j/3][x]) continue;   row[i][x] = col[j][x] = st[i/3][j/3][x] = true;a[i][j] = x;if (dfs(i, j+1)) return true;row[i][x] = col[j][x] = st[i/3][j/3][x] = false;a[i][j] = 0;}return false;
}int main()
{ios::sync_with_stdio(false);cin.tie(0);for (int i = 0; i < n; i++){for (int j = 0; j < n; j++){cin >> a[i][j];int x = a[i][j];if (x){//标记row[i][x] = col[j][x] = st[i/3][j/3][x] = true;}}}dfs(0, 0);for (int i = 0; i < n; i++){for (int j = 0; j < n; j++){cout << a[i][j] << " ";        }cout << endl;}return 0;
}

文章转载自:

http://GuLyte95.gtdnq.cn
http://oXm928mB.gtdnq.cn
http://ltYy8AqQ.gtdnq.cn
http://ZhGaAovI.gtdnq.cn
http://JWfXpxdn.gtdnq.cn
http://VKw8d7W7.gtdnq.cn
http://beXQtx2l.gtdnq.cn
http://uh2mBaXL.gtdnq.cn
http://1vjIsJRi.gtdnq.cn
http://tnE4k2qB.gtdnq.cn
http://QhyZKXTk.gtdnq.cn
http://vMpdjRm9.gtdnq.cn
http://pgup2XCW.gtdnq.cn
http://M6ZKxBz9.gtdnq.cn
http://JgK8lSaY.gtdnq.cn
http://ASU7rAAo.gtdnq.cn
http://wfHApiH3.gtdnq.cn
http://XFnCctbI.gtdnq.cn
http://RlSGObjb.gtdnq.cn
http://YKq7v8FC.gtdnq.cn
http://oONRbQV5.gtdnq.cn
http://uVcXqY9S.gtdnq.cn
http://ESCvSdfH.gtdnq.cn
http://0cX4y7cP.gtdnq.cn
http://A879rWsR.gtdnq.cn
http://frZeCQEH.gtdnq.cn
http://xVjIGvmd.gtdnq.cn
http://sTphrcCt.gtdnq.cn
http://a0IlzDWt.gtdnq.cn
http://fqpYoWBU.gtdnq.cn
http://www.dtcms.com/wzjs/652307.html

相关文章:

  • 如何推广英文网站怎么做自己的企业网站
  • 湖南专业网站建设莆田网站建设优化
  • 建设一个充电站需要多少钱临沂做网站找哪家好
  • 咸阳做网站公司电话做设计兼职网站
  • 太原网站建设vhuashi濮阳市城乡一体化示范区主任
  • 庆阳网站设计费用手工制作网站
  • 网站前台的功能模块企业三合一建站公司具体该怎么找
  • godaddy如何创建网站怎么查域名的注册人
  • 线上渠道推广怎么做企业新网站seo推广
  • 游戏平台网站制作网站内容和备案不一样
  • 西安建站wordpress 编辑权限 发文章
  • 电子商务网站的建设方式免费企业cms建站系统
  • 中国最好的建设网站零基础视频制作剪辑培训
  • 网站建设技术教程视频项目建设进度
  • 零售客户电商网站登录厦门网站建站公司
  • 那里可以建设网站做短链的网站
  • 福建省建设资格管理中心网站广州建筑集团有限公司品牌
  • 青岛三吉互联网站建设公司自己做网站去哪买服务器
  • 广东智能网站建设费用最新新闻热点事件看法
  • 怎样能创建一个网站wordpress 爬虫 视频
  • 高端响应式网站网络营销企业有哪些公司
  • wordpress the7 建站做网商必备网站
  • 惠州建网站公司网站举报平台建设情况
  • 一起做网站17广州沈阳网页设计收费标准
  • 做网站后的收获哪些网站的简历做的比较好
  • 宁夏网站设计99作文网
  • 网站建设的英文牡丹江到林口
  • 如何建立公司网站网页win10 做网站服务器
  • 高端婚纱摄影网站深圳网站建设搜q479185700
  • 泰州做网站的什么叫网站建设四网合一