文章分类 - DFS
摘要:吃奶酪 https://www.luogu.com.cn/problem/P1433 纯暴力DFS #include<bits/stdc++.h> using namespace std; struct point{ double x,y; bool visit; }ps[16]; int n; d
阅读全文
摘要:P1219 八皇后 Checker Challenge https://www.luogu.com.cn/problem/P1219 #include<iostream> #include<stdio.h> using namespace std; const int maxn=14; int cn
阅读全文
摘要:图的m着色问题 https://www.luogu.com.cn/problem/P2819 #include<bits/stdc++.h> using namespace std; const int MAXN=105; int f[MAXN][MAXN];//邻接矩阵存储 int color[1
阅读全文
摘要:全排列 http://noi.openjudge.cn/ch0202/1750/ #include<bits/stdc++.h> using namespace std; bool b[10001];//字符是否被用过 //s 输入的字符数组 ans本来输出的字符数组 char s[10001],a
阅读全文
摘要:组合的输出 https://www.luogu.com.cn/problem/P1157 #include<bits/stdc++.h> using namespace std; int n,r; bool v[50]; int f[50]; //now 用哪个数填 l填第几个空 void dfs(
阅读全文
摘要:放苹果 http://noi.openjudge.cn/ch0205/666/ 示例代码 #include<bits/stdc++.h>using namespace std; int dfs(int,int);//第一个赋值为1 其余为0 int a[11]={1},ans,n,m; int ma
阅读全文
摘要:马走日 http://noi.openjudge.cn/ch0205/8465/ 思路: 1. dfs参数:递归 到某个位置 和到此位置走的步数 2.八个方向递归访问对应棋盘位置 3. 下个要访问的位置在棋盘范围内 并且没有被访问过则继续递归 4.递归出口走过的步数和棋盘所有位置相等 示例代码 #i
阅读全文
摘要:棋盘问题 http://noi.openjudge.cn/ch0205/323/ 思路: 1.递归参数为落子当前行 和到目前位置落子数 2.引用一维数组记录是否同列 3.可以落子,则递归下一行和落子数+1 4.落子数达到k退出递归并累加方案数 示例程序 #include<bits/stdc++.h>
阅读全文
摘要:红与黑-计算可到达的瓷砖数 http://noi.openjudge.cn/ch0205/1818/ 思路: 1.从起点出发,往四个方向走 2.在范围内 路径通可以走,没走过,递归往下走 并记录走过步数 #include<bits/stdc++.h> using namespace std; cha
阅读全文
摘要:迷宫-是否可以到底某个坐标 http://noi.openjudge.cn/ch0205/1792/ 思路: 1.从起点出发,四个方向找 2.未找到继续往下找 找到则直接输出 #include<bits/stdc++.h> using namespace std; int dx[4]={1,-1,0
阅读全文
摘要:输出第几个八皇后 http://noi.openjudge.cn/ch0205/1756/ 思路: 1.按行递归 2. 每次递归,为此行放置皇后,有如下限制条件 本方案中此列已经放置过皇后不能放置 正斜线对角线放置过皇后不能放置 反斜线对角线放置过皇后不能放置 上面三种情况分别使用一个bool型一维
阅读全文
摘要:noi 输出 八皇后问题 http://noi.openjudge.cn/ch0205/1700/ 思路: 题意知八皇后中 行,列,正斜线对角线 /、反斜线对角线 \都不能存在两个或者两个以上 递归列,每列放一个皇后,放置过程中判断行、正斜线对角线 /、反斜线对角线 \都不能存在两个或者两个以上皇后
阅读全文
摘要:LETTERS http://noi.openjudge.cn/ch0205/156/ 给出一个roe*col的大写字母矩阵,一开始的位置为左上角,你可以向上下左右四个方向移动,并且不能移向曾经经过的字母。问最多可以经过几个字母 输入: 第一行,输入字母矩阵行数R和列数S,1<=R,S<=20 接着
阅读全文
摘要:八皇后 P1219 [USACO1.5]八皇后 Checker Challenge https://www.luogu.com.cn/problem/P1219 回溯法(探索与回溯法)是一种选优搜索法,又称为试探法,按选优条件向前搜索,以达到目标。但当探索到某一步时,发现原先选择并不优或达不到目标,
阅读全文