摘要:HDU-1298-T9http://acm.hdu.edu.cn/showproblem.php?pid=1298很好的一题,字典树+DFS,思路参考swm8023大牛的题意是模拟手机输入法,给出几个单词即频度,再给出几个数字串,确定对于给定的一个数字串,每输入一个数字,将显示什么字符本题的数字串的每一个数字均代表一个字母,而不是平常的手机,多个数字可能代表一个字母,首先可将给出的单词即频度记录到字典树中,对于数字串进行DFS,查找其可能表示的频度最大的字符串例如 ab 2 bc 3 2323代表的字符串可能是ad,ae,af,bd,be,bf,cd,ce,cf,逐个搜索,...
阅读全文
摘要:HDU-1427-速算24点http://acm.hdu.edu.cn/showproblem.php?pid=14274个数通过 +,—,*,/和加括号,计算得24,枚举数字和运算符,DFS即可,注意题目要求计算过程中都不能出现小数,所以做除法时稍作处理枚举数组可用algorithm里的next_permutationThe next_permutation() function attempts to transform the given range of elements [start,end) into the next lexicographically greater permu
阅读全文
摘要:POJ-1088-滑雪http://poj.org/problem?id=1088从每一个点深搜,果然超时了,因为这要重复计算很多次,优化一下,将搜索过的点记录下来,避免重复计算即可超时的代码#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int map[105][105];
int n1,n2,ans;
int dir[4][2]={{0,-1},{0,1},{-1,0},{1,0}};
int go(int x,int y)
{ if(0<=x&&x<n1&
阅读全文
摘要:HDU-2553-N皇后问题http://acm.hdu.edu.cn/showproblem.php?pid=2553基本的DFS,感觉DFS就像求全排列一样#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int n,ans;
int map[15];
int visit[15];
int sol[15];
void dfs(int k)
{ int i,j,flag; if(k==n+1) { ans++; return; } for(i=1;i<=n;i++) if(!visit[i
阅读全文