上一页 1 ··· 69 70 71 72 73 74 75 76 77 ··· 138 下一页
摘要: bfs图的时候需要注意判重。 八数码状态数 9!=362880 ,如果用9维的vis,9^9=387420489,会有很大的浪费。 有三种方法来解决空间浪费问题: 1、编码解码 这里用cantor编码 typedef int State[9];const int MAXSTATE = 1000000;State st[MAXSTATE], goal;int dist[MAXSTAT... 阅读全文
posted @ 2014-04-24 16:05 katago 阅读(272) 评论(0) 推荐(0)
摘要: http://zh.wikipedia.org/wiki/康托展开 http://www.nocow.cn/index.php/康托展开 http://blog.sina.com.cn/s/blog_4bf7b6580100l2zs.html http://www.skymoon.biz/?p=86 http://www.cnblogs.com/1-2-3/archive/2011/04/... 阅读全文
posted @ 2014-04-24 15:47 katago 阅读(201) 评论(0) 推荐(0)
摘要: 例7-3 倒水问题。 有装满水的6升的杯子、空的3升杯子和1升杯子,3个杯子中都没有刻度。在不使用其他道具的情况下,是否可以量出4升的水呢? 方法如图7-7所示。 图7-7 倒水问题:一种方法是(6,0,0)→(3,3,0)→(3,2,1)→(4,2,0) 注意:由于没有刻度,用杯子x给杯子y倒水时必须一直持续到把杯子y倒满或者把杯子x倒空,而不能中途停止。 你的任务是解决一般性... 阅读全文
posted @ 2014-04-21 20:30 katago 阅读(849) 评论(0) 推荐(0)
摘要: 通过swap方式生成的全排列并不是字典顺序的: #include#include#include#include#includeusing namespace std;int A[20];int cnt;int recur;void perm(int cur, int n, int *A){ recur++; if(cur==n)//empty { ... 阅读全文
posted @ 2014-04-19 14:22 katago 阅读(201) 评论(0) 推荐(0)
摘要: 1、增量构造法: 一次选出一个元素放到集合中,由于集合中的元素是无序的,所以我们从小到大生成所有元素。每次选择的元素都要比之前的大。 如上图,生成 {1, 2, 3} 的子集过程中的解答树。 共有2^n个节点(8个),每个节点都是解。 2、位向量法 每次有选和不选两种情况 {1 ,2 ,3} 子集的解答数 总共有 1+2+4+ … +2^n= 2^(n+1)... 阅读全文
posted @ 2014-04-17 19:35 katago 阅读(227) 评论(0) 推荐(0)
摘要: 7.2.1 生成1~n的全排列 #includeint A[100];// 输出1~n的全排列void print_permutation(int n, int* A, int cur) { int i, j; if(cur == n) { // 递归边界 for(i = 0; i #include#include#include#includeusing namespace ... 阅读全文
posted @ 2014-04-16 16:32 katago 阅读(642) 评论(0) 推荐(0)
摘要: 学习点: scanf可以自动过滤空行 搜索时要先判断是否越界(L R C),再判断其他条件是否满足 bfs搜索时可以在入口处(push时)判断是否达到目标,也可以在出口处(pop时) #include#include#include#include#includeusing namespace std;const int N=31;const int dl[]={-... 阅读全文
posted @ 2014-04-12 15:24 katago 阅读(390) 评论(0) 推荐(0)
摘要: bfs 最短路径 #include#include#include#include#include#includeusing namespace std;const int N=105;int n, m, rs, cs, rt, ct;typedef int A[N][N];A maze, vis, dist, last_dir;int dr[] = {-1,1,0,0};int dc... 阅读全文
posted @ 2014-04-12 13:47 katago 阅读(377) 评论(0) 推荐(0)
摘要: // 题意:输入标准国际象棋棋盘上的两个格子,求马最少需要多少步从起点跳到终点 BFS求最短路: bfs并维护距离状态cnt, vis记录是否访问过 #include#include#include#include#include#includeusing namespace std;int r1, c1, r2, c2;const int N=8;int vis[N][N];... 阅读全文
posted @ 2014-04-12 10:26 katago 阅读(745) 评论(0) 推荐(0)
摘要: // 题意:输入一个迷宫,从*开始遍历,把可达点标记为字符# 注意迷宫边界不规则,要用strlen判断。 #include#include#include#include#includeusing namespace std;const int maxn = 100 + 5;char maze[maxn][maxn];int dr[]={0, 0, -1, 1};int dc[]=... 阅读全文
posted @ 2014-04-10 17:46 katago 阅读(318) 评论(0) 推荐(0)
上一页 1 ··· 69 70 71 72 73 74 75 76 77 ··· 138 下一页