随笔分类 -  回溯法

摘要:题目连接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1035题目大意:给你一个黑白的棋盘,每次翻一个子(翻的子上下左右也自动翻),看最后能否返程全黑或者全白、最少要几次。View Code 1 #include <stdio.h> 2 #include <string.h> 3 int ans = 10000; 4 char map[10][10]; 5 int pan() 6 { 7 int i,j; 8 for(i = 0;i < 4;i++) 9 {1 阅读全文
posted @ 2012-11-06 18:09 某某。 阅读(183) 评论(0) 推荐(0)
摘要:不大明白啥叫记忆化搜索,但是PC学长说就相当于打表~不大懂= =。。。回头好好看一下题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1501参考着崔老师的代码来的。View Code 1 #include<stdio.h> 2 #include<string.h> 3 4 char s1[205],s2[205],s3[410]; 5 int len,count,vis[205][205],leap; 6 void dfs(int a,int b,int c) 7 { 8 if(leap) 9 return;10 if(v.. 阅读全文
posted @ 2012-08-01 22:18 某某。 阅读(196) 评论(0) 推荐(0)
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1372大体意思是给你一个8*8的棋盘,然后给你两个字母与数字的组合,字母代表的是行,数字代表咧,让你找出从第一个组合的位置到第二个组合的位置,至少要走多少步。View Code 1 #include<stdio.h> 2 #include<string.h> 3 struct node 4 { 5 int x,y,step; 6 }q[100005]; 7 int map[15][15]; 8 int pro[15][15]; 9 int to[8][2] = {{2,1}, 阅读全文
posted @ 2012-08-01 20:38 某某。 阅读(153) 评论(0) 推荐(0)
摘要:题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1253三维的BFS,跟地下城那道题很像。不用怎么解释。题目上说的很清楚。View Code 1 #include <stdio.h> 2 #include <string.h> 3 struct node 4 { 5 int x,y,z; 6 int t; 7 }q[1000005]; 8 int map[55][55][55]; 9 int pro[55][55][55],f,r;10 int to[6][3] = {{0,0,1},{0,0,-1},{0,1,0},{0,- 阅读全文
posted @ 2012-08-01 20:27 某某。 阅读(130) 评论(0) 推荐(0)
摘要:题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1241题目大意是@是可以走的,让你找出是不是有几块是连载一起的。跟挑战编程上的一道题木很想、View Code 1 #include <stdio.h> 2 #include <string.h> 3 4 char map[110][110]; 5 int vis[110][110]; 6 int to[8][2] = {{0,1},{0,-1},{1,0},{1,1},{1,-1},{-1,0},{-1,1},{-1,-1}}; 7 int n,m,count; 8 9 vo 阅读全文
posted @ 2012-08-01 20:25 某某。 阅读(141) 评论(0) 推荐(0)
摘要:题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1015题目的大意就是给以一串字符串和一个目标数字,让你从中找出5个字母,依次可以满足v - w^2 + x^3 - y^4 + z^5 = target这个关系式如果有多个就按字典序最大的输出。。。View Code #include <stdio.h>#include <string.h>#include <stdlib.h>int vis[100005];char str[100005];int sum,leap;char end[10],temp[10];in 阅读全文
posted @ 2012-08-01 20:21 某某。 阅读(250) 评论(0) 推荐(0)
摘要:View Code // Little Bishops (棋盘上的象)// PC/UVa IDs: 110801/861, Popularity: C, Success rate: high Level: 2// Verdict: Accepted // Submission Date: 2011-06-19// UVa Run Time: 0.024s//// 版权所有(C)2011,邱秋。metaphysis # yeah dot net//// n * n 的棋盘可以最多放置多少个象而不互相冲突?我是这样考虑的,因为象的吃子方式为// 对角线吃子,则在棋盘上放置一个象后,它要么占据一条对 阅读全文
posted @ 2012-07-25 19:12 某某。 阅读(469) 评论(0) 推荐(0)
摘要:View Code #include<stdio.h>void process(int a[],int k){ int i; for(i = 1;i <= k;i++) printf("%d ",a[i]); puts("");}int construct(int a[],int k,int n,int c[]){ int i; int pre[100]; for(i = 1;i < 100;i++) pre[i] = 0; for(i = 1;i < k;i++) pre[a[i]] = 1; int n2 = 0; f. 阅读全文
posted @ 2012-07-25 15:42 某某。 阅读(192) 评论(0) 推荐(0)
摘要:这道题是自己写着玩的,看看能不能掌握简单的回溯,是挑战编程上的一个小程序自己打下来的。留个纪念。还有一个回溯是一个牛喝水的那一道。八皇后就不多少了,我想基本提到回溯法的树上都会提及八皇后和它的代码。View Code #include <stdio.h> #include <stdlib.h> int leap = 0; void process(int a[],int k) { printf("{"); int i; for(i = 1;i <= k;i++) if(a[i]) printf(" %d",i); print 阅读全文
posted @ 2012-07-22 20:05 某某。 阅读(181) 评论(0) 推荐(0)