思想:存三个数组记录记录走的过程,运用回溯不符合或row==n+1就跳出当前层,直到找完;递归时的路径都在保存着,当连续跳出到第一次进入的dfs且i=n时就全部跳出dfs函数了; 1 #include 2 #include 3 int n,sum; 4 int visit[3][100]; 5...
分类:
其他好文 时间:
2015-08-03 19:05:04
阅读次数:
93
貌似uva崩了,现在进不去,所以这道题还判断正确与否,其实无所谓了,我这是看的网上的代码,写的基本上一样,唉,没办法,不会做,又看了网上的题解,认真写理解吧还是。。。
构造了一个结构体,water数组用来保存三个杯子的状态,sum用来保存当前的倒水量,visit数组用来保存状态,以
防他们重复访问,三个杯子只需要两个杯子来判断,第三个已经确定,所以开一个二维数组就可以了。。。然后用
reac...
分类:
其他好文 时间:
2015-07-30 13:32:32
阅读次数:
147
#include #include #include using namespace std;#define max (a>b)?a:bconst int nMax = 105;int map[nMax][nMax];int d[nMax][nMax];int visit[nMax];struct ...
分类:
其他好文 时间:
2015-07-30 11:10:56
阅读次数:
141
substring() 从字符串中提取一些字符var str="Hello world!"document.write(str.substring(3))stringObject.replace(regexp/substr,replacement)var str="Visit Microsoft!"...
分类:
编程语言 时间:
2015-07-29 15:33:42
阅读次数:
143
非自己出品就是容易wa啊,想了一会没想出来,就忍不住去找答案了,实在没忍住去找答案,结果还是wa了两
次,,,还是自己想的比较靠谱啊,
思路:
如果当前点可以被染成黑色,就把它染成黑色,继续深搜,之后回溯,把它染成白色
如果当前点只能被染成白色,就染成白色深搜
代码:
#include
#include
#include
int map[105][105];
int visit[10...
分类:
其他好文 时间:
2015-07-29 10:17:40
阅读次数:
112
poj 2253 FroggerDescription
Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dir...
分类:
其他好文 时间:
2015-07-25 15:17:16
阅读次数:
138
拓扑排序,不用判断是否有环,dfs挺简单的
代码:
#include
#include
#include
int map[105][105];
int visit[105];
int c[105];
int n,m,t;
void dfs(int x)
{
visit[x] = 1;
for(int i=1; i<=n; i++)
{
if(!visit[i]&&map[i][x]=...
分类:
编程语言 时间:
2015-07-24 00:00:33
阅读次数:
410
第一次用vector解得题,值得纪念,这道题是二染色问题,我用bfs解得,就是染色,判断,计数问题,其
实挺简单的,就是得判一下特殊情况,当n
人的时候就是一个组是n-1,另一个组人数为1
上代码:
#include
#include
#include
#include
#include
#include
using namespace std;
int visit[100005];
i...
分类:
其他好文 时间:
2015-07-23 21:56:37
阅读次数:
112
这道题以前写过,bfs,用队列,不多说了,上代码:
#include
#include
#include
#include
using namespace std;
int map[10][10];
int visit[10][10];
int dist[10][10];
int dx[8]={-2,-2,-1,-1,1,1,2,2};
int dy[8]={-1,1,-2,2,-2,2,-1,...
分类:
移动开发 时间:
2015-07-22 16:22:42
阅读次数:
148
题目地址:http://poj.org/problem?id=1028测试样例:Sample InputVISIT http://acm.ashland.edu/VISIT http://acm.baylor.edu/acmicpc/BACKBACKBACKFORWARDVISIT http://w...
分类:
Web程序 时间:
2015-07-21 22:00:26
阅读次数:
266