
ACM_DFS
文章平均质量分 65
Cambridge
不做下一个谁,先做第一个我
展开
-
HDU-1010-Tempter of the Bone
HDU-1010-Tempter of the Bonehttp://acm.hdu.edu.cn/showproblem.php?pid=1010给这题折腾了半天啊,刚开始用BFS写的,总是WA,后来发现这题要求在给定的时间点到达,不能早,也不能迟,而BFS每次求出的是最短时间,不合题意,于是转用DFS,剪枝的方法是参考HDU的PPT写的,居然还要考虑奇偶性可以把map看成这样:原创 2012-07-08 17:01:20 · 922 阅读 · 0 评论 -
HDU-1501-Zipper
HDU-1501-Zipperhttp://acm.hdu.edu.cn/showproblem.php?pid=1501基本的DFS,注意搜索过的状态要标记,不然会超时#include#include#includechar str1[205],str2[205],str3[405];int flag;int len1,len2,len3;int hash[205][原创 2012-07-27 21:06:05 · 1948 阅读 · 0 评论 -
HDU-1016-Prime Ring Problem
HDU-1016-Prime Ring Problemhttp://acm.hdu.edu.cn/showproblem.php?pid=1016基本的DFS,先打个素数表即可#include#include#includeint prime[50];int visit[30];int num[30];int n;void init(){ int i,j;原创 2012-07-27 20:50:14 · 1102 阅读 · 0 评论 -
HDU-1258-Sum It Up
HDU-1258-Sum It Uphttp://acm.hdu.edu.cn/showproblem.php?pid=1258注意每个数只能用一次,且不能出现重复的等式#include#include#includeint a[20],ans[20];int sum,n,flag;void dfs(int x,int count,int m){ int i,last;原创 2012-07-27 09:30:54 · 2132 阅读 · 0 评论 -
HDU-1298-T9
HDU-1298-T9http://acm.hdu.edu.cn/showproblem.php?pid=1298很好的一题,字典树+DFS,思路参考swm8023大牛的题意是模拟手机输入法,给出几个单词即频度,再给出几个数字串,确定对于给定的一个数字串,每输入一个数字,将显示什么字符本题的数字串的每一个数字均代表一个字母,而不是平常的手机,多个数字可能代表一个字母,首先可将给出的原创 2012-07-17 22:45:30 · 2843 阅读 · 0 评论 -
HDU-1427-速算24点
HDU-1427-速算24点http://acm.hdu.edu.cn/showproblem.php?pid=14274个数通过 +,—,*,/和加括号,计算得24,枚举数字和运算符,DFS即可,注意题目要求计算过程中都不能出现小数,所以做除法时稍作处理枚举数组可用algorithm里的next_permutationThe next_permutation() functi原创 2012-07-16 15:11:33 · 5942 阅读 · 0 评论 -
POJ-1088-滑雪
POJ-1088-滑雪http://poj.org/problem?id=1088从每一个点深搜,果然超时了,因为这要重复计算很多次,优化一下,将搜索过的点记录下来,避免重复计算即可超时的代码#include#include#includeint map[105][105];int n1,n2,ans;int dir[4][2]={{0,-1},{0,1},{-1,0原创 2012-07-15 11:38:42 · 868 阅读 · 0 评论 -
POJ-1321-棋盘问题
POJ-1321-棋盘问题http://poj.org/problem?id=1321基本的DFS#include#include#includeint n,t,ans;char map[10][10];int visit[10];void dfs(int x,int y){ int i; if(y==t) { ans++; return; } if(x原创 2012-07-12 19:17:18 · 965 阅读 · 0 评论 -
HDU-1244-Oil Deposits
HDU-1244-Oil Depositshttp://acm.hdu.edu.cn/showproblem.php?pid=1241基本的DFS#include#include#includechar map[105][105];int n,m;int dir[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1原创 2012-07-12 18:22:58 · 1232 阅读 · 0 评论 -
POJ-2488-A Knight's Journey
POJ-2488-A Knight's Journeyhttp://poj.org/problem?id=2488给一个n1*n2的棋盘,从(0,0)出发,每次走日字形,能否不重复的遍历所有的点用DFS即可,需要注意搜索的方向要按字典序 #include#include#includeint n1,n2;int xx[30],yy[30];int visit[30][30原创 2012-07-12 22:19:32 · 2956 阅读 · 1 评论 -
HDU-2553-N皇后问题
HDU-2553-N皇后问题http://acm.hdu.edu.cn/showproblem.php?pid=2553基本的DFS,感觉DFS就像求全排列一样#include#include#includeint n,ans;int map[15];int visit[15];int sol[15];void dfs(int k){ int i,j,fl原创 2012-06-29 21:05:51 · 5662 阅读 · 2 评论 -
HDU-1520-Anniversary party
HDU-1520-Anniversary partyhttp://acm.hdu.edu.cn/showproblem.php?pid=1520DFS,有些节点具有父子关系,要求具有父子关系的节点不能同时出现#include#include#include#define N 6001struct node //左二子右兄弟法建树{ int parent; in原创 2012-07-30 10:23:03 · 1355 阅读 · 0 评论