Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 151147    Accepted Submission(s): 40285 Problem Description The doggie found a bone in an ancient maze, which fascinated him a…
Tempter of the Bone 直接上中文了 Descriptions: 暑假的时候,小明和朋友去迷宫中寻宝.然而,当他拿到宝贝时,迷宫开始剧烈震动,他感到地面正在下沉,他们意识到这是一个陷阱!他们想尽一切办法逃出去.迷宫是一个大小为 N*M 的长方形,迷宫中有一扇门.一开始,门是关着的,他会在第 t 秒的时间打开.因为,小明和朋友必须在第 t 秒到大门口.每一秒,他都可以向上下左右四个方向移动一个点.一旦他移动了,他刚才所在的点就消失,(这意味着他不能回到他已经走过的点).他不能在一个…
http://acm.hdu.edu.cn/showproblem.php?pid=1010 给出一个n*m的迷宫 X为墙 .为空地 S为起点 D为终点 给出时间T 每走一步花费一单位的时间 走过的空地会消失不能再次经过 问能不能刚好花费T单位时间到达终点(在T时间前到达终点也算失败) 典型深搜 为减少时间花费加点剪枝 1.奇偶剪枝:给出一个01矩阵如下 从0到0或从1到1 必然要经过偶数步 从0到1或从1到0 必然要经过奇数步 所以可以通过比较起点终点的属性 判明是否已经是不可能到达的 2.如…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 102071    Accepted Submission(s): 27649 Problem Description The doggie found a bone in an ancient maze, which fascinated him…
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1010 Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 69549    Accepted Submission(s): 19126 Problem Description The doggie foun…
Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone was a trap, and he tried despe…
题意:从S走到D,能不能恰好用T时间. 析:这个题时间是恰好,并不是少于T,所以用DFS来做,然后要剪枝,不然会TEL,我们这样剪枝,假设我们在(x,y),终点是(ex,ey), 那么从(x, y)到(ex, ey),要么时间正好是T-你已经走过的时间,要么要向别的地方先拐一下,以凑出这个正好时间,既然要拐一下,那么一定要回来, 所以时间肯定得是偶数,要不然完不成(回不来), 所以(t - abs(ex-x) - abs(ey-y) - cnt ),如果是奇数就剪枝.然而用C++交就TLE,用G…
题意:输入x,y,t.以及一个x行y列的地图,起点‘S’终点‘D’地板‘.’墙壁‘X’:判断能否从S正好走t步到D. 题解:dfs,奇偶性减枝,剩余步数剪枝. ps:帮室友Debug的题:打错了两个字母.题目看错.没有初始化map.orz ...不过我dfs也不熟,更别说剪枝了. //#include <bits/stdc++.h> #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstdio>…
小明做了一个很久很久的梦,醒来后他竟发现自己和朋友在一个摇摇欲坠的大棋盘上,他们必须得想尽一切办法逃离这里.经过长时间的打探,小明发现,自己所在的棋盘格子上有个机关,上面写着“你只有一次机会,出发后t秒大门会为你敞开”,而他自己所在的棋盘是大小为 N*M 的长方形,他可以向上下左右四个方向移动(不可走有障碍点).棋盘中有一扇门.根据机关的提示,小明顿时明白了,他和朋友必须在第 t 秒到门口.而这一切,没有回头路!因为一旦他移动了,他刚才所在的点就会消失,并且他不能在一个点上停留超过一秒,不然格子…
题目链接:pid=1010">点击打开链接 题目描写叙述:给定一个迷宫,给一个起点和一个终点.问是否能恰好经过T步到达终点?每一个格子不能反复走 解题思路:dfs+剪枝 剪枝1:奇偶剪枝,推断终点和起点的距离与T的奇偶性是否一致,假设不一致,直接剪掉 剪枝2:假设从当前到终点的至少须要的步数nt加上已经走过的步数ct大于T,即nt+ct>t剪掉 剪枝3:假设迷宫中能够走的格子小于T直接剪掉 启示:剪枝的重要性 代码: #include <cstdio> #include…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 58766    Accepted Submission(s): 15983 Problem Description The doggie found a bone in an ancient maze, which fascinated him a…
一.题目回顾 题目链接:Tempter of the Bone Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bon…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake…
Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9779    Accepted Submission(s): 2907 Problem Description George took sticks of the same length and cut them randomly until all parts became…
POJ3009 DFS+剪枝 原题: Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16280 Accepted: 6725 Description On Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are somewhat different from our…
ROADS Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10777   Accepted: 3961 Description N cities named with numbers 1 ... N are connected with one-way roads. Each road has two parameters associated with it : the road length and the toll…
题目传送门 /* 题意:若干小木棍,是由多条相同长度的长木棍分割而成,问最小的原来长木棍的长度: DFS剪枝:剪枝搜索的好题!TLE好几次,终于剪枝完全! 剪枝主要在4和5:4 相同长度的木棍不再搜索:5 若新的搜索连第一条都没组合出来,直接break: 详细解释:http://blog.csdn.net/lyy289065406/article/details/6647960 http://www.cnblogs.com/devil-91/archive/2012/08/03/2621787.…
题目传送门 /* 题意:告诉一个区间[L,R],问根节点的n是多少 DFS+剪枝:父亲节点有四种情况:[l, r + len],[l, r + len - 1],[l - len, r],[l - len -1,r]; */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <queue> using namespace std;…
Counting Cliques Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 539    Accepted Submission(s): 204 Problem Description A clique is a complete graph, in which there is an edge between every pair…
Equation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 92    Accepted Submission(s): 24 Problem Description Little Ruins is a studious boy, recently he learned addition operation! He was rewa…
题目链接 Solution DFS+剪枝 对于一个走过点k,如果有必要再走一次,那么一定是走过k后在k点的最大弹药数增加了.否则一定没有必要再走. 记录经过每个点的最大弹药数,对dfs进行剪枝. #include <iostream> #include <cstring> #include <algorithm> #include <cstdio> #include <map> using namespace std; map<string…
Sticks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 127771   Accepted: 29926 Description George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the or…
Sum It Up Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 4   Accepted Submission(s) : 1 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description Given a specified total t and…
求最久时间即在无环有向图里求最远路径 dfs+剪枝优化 从0节点(自己添加的)出发,0到1~n个节点之间的距离为1.mt[i]表示从0点到第i个节点眼下所得的最长路径 #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<vector> using namespace std; const…
题目大意:原题链接 给定n个节点,任意两个节点之间有权值,把这n个节点分成A,B两个集合,使得A集合中的每一节点与B集合中的每一节点两两结合(即有|A|*|B|种结合方式)权值之和最大. 标记:A集合:true  B集合:false 解法一:dfs+剪枝 #include<iostream> #include<cstring> using namespace std; int n,ans; ]; ][]; void dfs(int i,int cursum) { in[i]=tru…
HDU 1501 Zipper [DFS+剪枝] Problem Description Given three strings, you are to determine whether the third string can be formed by combining the characters in the first two strings. The first two strings can be mixed arbitrarily, but each must stay in…
HDOJ 1501 Zipper [DP][DFS+剪枝] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10886 Accepted Submission(s): 3925 Problem Description Given three strings, you are to determine whether the third str…
题意:给出n根小棒的长度stick[i],已知这n根小棒原本由若干根长度相同的长木棒(原棒)分解而来.求出原棒的最小可能长度. 思路:dfs+剪枝.蛮经典的题目,重点在于dfs剪枝的设计.先说先具体的实现:求出总长度sum和小棒最长的长度max,则原棒可能的长度必在max~sum之间,然后从小到大枚举max~sum之间能被sum整除的长度len,用dfs求出所有的小棒能否拼凑成这个长度,如果可以,第一个len就是答案. 下面就是关键的了,就是这道题dfs的实现和剪枝的设计: 1.以一个小棒为开头…
Black And White Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)Total Submission(s): 3937    Accepted Submission(s): 1082Special Judge Problem Description In mathematics, the four color theorem, or the four color…
题目链接: codeforces 615 B. Longtail Hedgehog (DFS + 剪枝) 题目描述: 给定n个点m条无向边的图,设一条节点递增的链末尾节点为u,链上点的个数为P,则该链的beauty值 = P*degree[u].问你所有链中最大的beauty值. 解题思路: 因为只需要找到以每个节点为终点的最长递增链即可,所以建图的时候可以建成从编号小的节点到编号大的节点的有向图,然后用DFS搜索,但是直接暴搜会TLE,然后就开始了我的TLE之路,TLE24, TLE42,TL…