class Solution {
public:
void dfs(vector<vector >&result, vectorcombination, vector&candidates, int kth, int k, int index2add){
// 当前正在确定组合中的第kth个数,将把候选集candidates中index2add索引位的值作为第kth个数加到组合中
combination.push_back(ca...
分类:
其他好文 时间:
2014-06-07 01:21:47
阅读次数:
220
房间是N行N列的矩阵,其中0代表空的地板,1代表墙,2代表箱子的起始位置,3代表箱子要被推去的位置,4代表搬运工的起始位置,求最后搬运工推箱子的步数。
问题实质就是五个状态:箱子的位置(bx,by),人的位置(px,py),推箱子的步数。然后用广搜去一一搜索。...
分类:
其他好文 时间:
2014-06-05 11:00:07
阅读次数:
230
最短路条数:
求一个图一共一几条最短路径,思路:先从终点跑一边最短路,记录终点到到所有点最短距离(d【i】),然后从起点出发,dfs 按d[i]走(必是最短路径),一句话:我到终点的最短路条数=我的所有孩子到终点的最短路条数之和,这样只需一遍即可。这不知道是不是叫记忆化搜索?
边不可重复最短路径条数:(最短路+建新图之最大流)
hdu3599题意:求1-->n最短路条数,所有路径边不可重复。思路:边不可重复??!!转为流量的为1 的话,求最大流啊(以后切记该方法,不可重复问题...
分类:
其他好文 时间:
2014-06-05 09:36:43
阅读次数:
237
一切见注释。
#include
#include
#include
#include
using namespace std;
bool vis[22];
int n;
int ans[22];
int top;
bool isprime(int x)//判断素数
{
for(int i=2;i<x;i++)
if(x%i==0)return false;
...
分类:
其他好文 时间:
2014-06-05 08:26:47
阅读次数:
201
题意:求'X'围成的周长
思路:按理说每增加一个就是周长加4,但是要减去重复的地方,这里我是用BFS做的,如果是BFS的模板思路的话是不行的,应该要先取出再标记
#include
#include
#include
#include
#include
using namespace std;
const int MAXN = 30;
struct node {
int x,y;
...
分类:
其他好文 时间:
2014-06-05 06:23:39
阅读次数:
221
题目描述 Description
一个大小为N(N
输入描述 Input Description
只有一个数N,表示需求的质数环的大小。如:
输出描述 Output Description
每一行描述一个数环,如果有多组解,按照字典序从小到大输出。如:
样例输入 Sample Input
6
...
分类:
其他好文 时间:
2014-06-04 21:44:09
阅读次数:
328
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a number line and the cow is at a point K (0 ≤ K ≤ 100,0...
分类:
其他好文 时间:
2014-06-03 05:30:23
阅读次数:
394
Knight Moves
Time Limit: 1000MS
Memory Limit: 30000K
Total Submissions: 20913
Accepted: 9702
Description
Background
Mr Somuro...
分类:
其他好文 时间:
2014-06-03 04:02:09
阅读次数:
260
不断找增广路,直到没有增广路,每找到一条增广路匹配数就加1 //hungary const
int X=100,Y=100;int match[Y];// initial to -1bool vis[Y];int g[X][Y];bool
dfs(int x){ for(int y=1;y<=Y;y...
分类:
其他好文 时间:
2014-05-31 20:49:41
阅读次数:
247
题目大意:
一个农主寻找牛。给出农主的位置n和牛的位置k。农主可以通过n-1或者n+1或者n*2的步伐找牛,问至少多少步才能找到自己的牛。解题思路:
简单的BFS。把农主的每一种可能的步伐通过BFS存到栈中,然后看最少多少步到达K坐标。代码: 1 #include 2 #include 3 ...
分类:
其他好文 时间:
2014-05-31 15:27:27
阅读次数:
252