随笔分类 -  搜索

 
HDU 2209 翻纸牌游戏
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2209艰难的一题,对回溯法的理解又深刻了View Code #include <iostream>using namespace std ;int q[25] ;int cnt[25] ;int len ;int ans ;bool gao(){ for(int i=0;i<len;i++) if(q[i]) return false ; return true ;}void dfs(int idx){ if(gao()) { int ... 阅读全文
posted @ 2012-06-06 20:27 LegendaryAC 阅读(457) 评论(2) 推荐(0)
HDU 1495 非常可乐
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1495bfs,个人感觉很经典的题目,分六种情况搜索View Code #include <iostream>using namespace std ;int s,n,m ;int q[101*101*101][3] ;int dp[101][101][101] ;int bfs(){ if(s&1) return 0 ; if(n<(s>>1)) return 0 ; dp[s][0][0]=0 ; int front=0,rear=1 ; q[fro... 阅读全文
posted @ 2012-06-06 11:07 LegendaryAC 阅读(696) 评论(0) 推荐(0)
HDU 1010 Tempter of the Bone
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1010奇偶剪枝,说好的里程碑来了。。。跳出dfs的时候一定要注意确保跳出。。。我开始写的时候没有跳出dfs只是跳出了一层递归,导致长时间tle,orz涂涂能看出这种问题。View Code #include <iostream>#include <queue>using namespace std ;int n,m,t ;int flag ;int e ;char map[10][10] ;void dfs(int x,int y,int time){ int tab[][2]={1, 阅读全文
posted @ 2012-06-05 17:18 LegendaryAC 阅读(179) 评论(0) 推荐(0)
HDU 1035 Robot Motion
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1035搜搜搜View Code #include <iostream>using namespace std ;char map[11][11] ;int dp[11][11] ;int n,m ;int ans,loop ;int flag ;void dfs(int x,int y,int cnt){ if(x<0 || x>=n || y<0 || y>=m) { flag=0 ; ans=cnt ; return ; } if(dp[x... 阅读全文
posted @ 2012-06-04 23:30 LegendaryAC 阅读(191) 评论(0) 推荐(0)
HDU 1312 Red and Black
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1312从这老题开始吧View Code #include <iostream>#include <queue>using namespace std ;char map[25][25];int ans,n,m;typedef struct L{ int x,y;}L;void bfs(int x,int y){ queue <L> q ; int tab[][2]={1,0,-1,0,0,1,0,-1}; L point,go,front; point.x=x; point 阅读全文
posted @ 2012-06-04 18:29 LegendaryAC 阅读(167) 评论(0) 推荐(0)
HDU 1016 Prime Ring Problem
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1016经典问题,素数环。直接回溯即可。View Code #include <stdio.h>#include <string.h>int n;int a[30];int prime[100],vis[30];void dfs(int cur){ if(cur==n && prime[a[0]+a[n-1]]==0) { printf("%d",a[0]); for(int i=1;i<n;i++) printf(" %d" 阅读全文
posted @ 2012-05-28 12:37 LegendaryAC 阅读(169) 评论(0) 推荐(0)
HDU 1027 Ignatius and the Princess II
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1027求数列n的第m个排列,STL中next_permutation的应用。相对应的还有prev_permutation。View Code #include #include #include #include using namespace std;int main(){ int n,m,i; int s[1100]; while(~scanf("%d%d",&n,&m)) { for(i=1;iusing namespace std ;int n,m ;int vi. 阅读全文
posted @ 2012-05-10 17:08 LegendaryAC 阅读(198) 评论(0) 推荐(0)
HDU 1181 变形课
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1181直接bfs,等号写成赋值了,wa两次。。。View Code #include <stdio.h>#include <string.h>char s[200];char graph[50][50];char vis[50];int q[50];int bfs(){ int front=0,rear=1; int ch,i; q[0]=1; while(front<rear) { ch=q[front++]; if(ch=='m'-'a')re 阅读全文
posted @ 2012-04-11 13:04 LegendaryAC 阅读(210) 评论(0) 推荐(0)