这次马踏棋盘是用递归实现的,而且可以弄出来所有解,当时电脑跑的最快的都有40多万解了,这个也可以看你电脑cpu好坏,一般超级本跑不动。这是实际上和八皇后是同一种性质的问题,都用到了回溯的思想,有接进行下一个,不行了退回去,在进行尝试。不多说了,直接上代码;
#include
#include
#include
#define N 8
int cnt=1; // 记录马的位置
i...
分类:
其他好文 时间:
2015-01-26 17:07:46
阅读次数:
574
Problem I
23 Out of 5
Input: standard input
Output: standard output
Time Limit: 1 second
Memory Limit: 32 MB
Your task is to write a program that can decide whether you can find an arithmetic ex...
分类:
其他好文 时间:
2015-01-26 17:07:04
阅读次数:
183
八皇后的问题和马踏棋盘的思路是一样,都用到了回溯的思想。代码也都差不多。这个里面最精彩的地方用4个一位数组表示了这个棋盘。这个里面总共有92组解
代码展示
#include
#include
int col[8]={0};
int right[15]={0};
int left[15]={0};
int Queen[8];
i...
分类:
其他好文 时间:
2015-01-26 17:05:35
阅读次数:
182
How Big Is It?
Ian's going to California, and he has to pack his things, including his collection of circles. Given a set of circles, your program must find the smallest rectangular box in...
分类:
其他好文 时间:
2015-01-26 17:05:21
阅读次数:
265
Given a string containing only digits, restore it by returning all possible valid IP address combinations.
For example:
Given "25525511135",
return ["255.255.11.135", "255.255.111.35"]. (Order ...
分类:
其他好文 时间:
2015-01-25 18:19:01
阅读次数:
219
题目:
Given a string s, partition s such that every substring of the partition is a palindrome.
Return all possible palindrome partitioning of s.
For example, given s = "aab",
Return
[
...
分类:
编程语言 时间:
2015-01-25 16:41:55
阅读次数:
201
原题地址非常有技巧性的一道题,虽然本质上仍然是搜索+回溯,但关键是如何处理模式串里的多余的*,如果处理的不好就超时了。基本的搜索+回溯算法是这样的,对于原串s和模式串p,依次遍历其字符:(a) 如果p[j]="*",依次将p[j+1..p.length]和s[i..s.length]、s[i+1.....
分类:
其他好文 时间:
2015-01-24 17:12:29
阅读次数:
190
hdu 5113 Black And White (dfs回溯+剪枝)—— black 的专栏 —— waShaXiu...
分类:
其他好文 时间:
2015-01-23 23:05:18
阅读次数:
229
Given a 2D board and a word, find if the word exists in the grid.
The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically...
分类:
其他好文 时间:
2015-01-23 18:30:06
阅读次数:
167
原题地址回溯,没啥好说的 1 bool row[9][9]; 2 bool col[9][9]; 3 bool grid[9][9]; 4 bool mark[9][9]; 5 6 bool solve(vector > &board, int r, int c) { 7 if (r == 9...
分类:
其他好文 时间:
2015-01-23 18:08:44
阅读次数:
135