联通块是指给定n个点,输入a,b(1#includeusing namespace std;const int maxn=1010;int p[maxn];//作为每个独立的点 int sum[maxn];//每个节点下面连接的点 int find(int x) {if(x==p[x])return...
分类:
移动开发 时间:
2014-07-14 22:21:30
阅读次数:
403
这同样是一道搜索题,所不同的是要搜索的图是三维的而不是二维的。但这并没什么大的改变,只是增加了两个搜索的方向而已。
要注意的地方是,所给出的起点终点的坐标是按照 列,行,层的顺序。
与DFS不同,BFS能保证所搜到的路径一定是最短路径,所以我们不需要维护一个多维(此处为3维)数组来记录访问到每一点的最小步数,只需要维护一个多维数组来标记是否走过就可以了。DFS中是要不停回溯来找最短路径的,但是BFS是不需要的。这是BFS本身的性质所决定的,BFS能保证第一次搜索到某一点时所走的路径就是到该点的最短路径。以后...
分类:
其他好文 时间:
2014-07-14 13:42:05
阅读次数:
181
dp[i][j]表示从i,j开始的最长路径,记忆化搜索一下。#include #include #include using namespace std;#define maxn 120int dp[maxn][maxn],map[maxn][maxn];int r,c;int dfs(int i,...
分类:
其他好文 时间:
2014-07-13 23:46:25
阅读次数:
259
1 #include 2 #include 3 #include 4 #include 5 #define MAXN 25 6 using namespace std; 7 int h,w; 8 int ans; 9 int dir[4][2]={-1,0,1,0,0,-1,0,1};10 cha....
分类:
其他好文 时间:
2014-07-13 20:30:45
阅读次数:
215
The Settlers of Catan题意:求最长路径#include #include int maxstep;int s[100][100];int n, m;void dfs(int v, int c){ int i; if(maxstep < c) maxste...
分类:
其他好文 时间:
2014-07-13 20:05:02
阅读次数:
181
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2136
Problem A
Another n-Queen Problem
I guess the n-queen problem is known by every ...
分类:
其他好文 时间:
2014-07-13 18:16:11
阅读次数:
498
题意:求0-B的满足
思路:数位DP,记忆化搜索
#include
#include
#include
#include
using namespace std;
int A, B;
int dp[20][200000];
int bit[20];
int dfs(int cur, int num, int flag) {
if (cur == -1)
return num ...
分类:
其他好文 时间:
2014-07-13 00:02:35
阅读次数:
338
第一次接触二分图匹配。
这题是一个匈牙利算法的模板题直接套就行。
题意是 给你奶牛和谷仓的个数a和b,接下来a行是奶牛喜欢去的谷仓。第一个是谷仓个数,接下来是谷仓编号。
这里我们把行当奶牛,列当谷仓。
在套模板。。ok;#include
#include
int map[1005][1005];
int a,b,link[1005],use[1005];
int dfs(int cap...
分类:
其他好文 时间:
2014-07-12 18:31:19
阅读次数:
245
汉诺塔VIII,在经典汉若塔问题上,问n个盘子的情况下,移动m次以后,是什么状态。
我的思路:本质还是dfs,但是用m的值来指引方向,每搜一层确定第i个盘子在哪个塔,o(n)的算法,看图说明:...
分类:
其他好文 时间:
2014-07-12 18:11:47
阅读次数:
214
一个很有意思的 BFS+DFS。附 数据。
本来今天的任务是多重背包,结果为了帮别人找WA点,自己也坑在这道题上了。
最好想了一组自己都没过的数据……果断换思路了。
以箱子为起点做BFS找最短。每次DFS判断人能不能移动到箱子的后面。
开始就我写一个BFS,什么数据都过了。这组过不了
1
7 4
0 0 0 0
0 0 1 0
0 2 0 3
1...
分类:
其他好文 时间:
2014-07-12 16:57:02
阅读次数:
214