package Mypackage; import java.util.Scanner; public class 全排列{ static int a[]=new int[10]; static int book[]=new int[10]; static int n=0; static void dfs(int step)//step表示出现在第几个盒子里面前 { int i; if(step==n+1)//如果站在第n+1个盒子面前,则表示前n个盒子已经放好扑克牌. { for(i=1;…
深度搜索 走地图的题目是深度搜索里比较容易理解的题目,更深层次的是全排列和七皇后等经典题目,更加难以理解,代码比较抽象. 题目:红与黑 蒜厂有一间长方形的房子,地上铺了红色.黑色两种颜色的正方形瓷砖.你站在其中一块黑色的瓷砖上,只能向相邻的黑色瓷砖移动. 请写一个程序,计算你总共能够到达多少块黑色的瓷砖. 输入格式 第一行是两个整数 WW 和 HH,分别表示 xx 方向和 yy 方向瓷砖的数量.WW 和 HH 都不超过 2020. 在接下来的 HH 行中,每行包括 WW 个字符.每个字符表示一块…
在Linux系统当中,如何搜.索查找文件里面的内容呢? 这个应该是系统维护.管理当中遇到最常见的需求.那么下面介绍,总结一下如何搜索.查找文件当中的内容. 搜索.查找文件当中的内容,一般最常用的是grep命令,另外还有egrep, vi命令也能搜索文件里面内容 1:搜索某个文件里面是否包含字符串,使用grep "search content" filename1, 例如 $ grep ORA alert_gsp.log $ grep "ORA" alert_gsp.…
Problem Description 蜘蛛牌是windows xp操作系统自带的一款纸牌游戏,游戏规则是这样的:只能将牌拖到比她大一的牌上面(A最小,K最大),如果拖动的牌上有按顺序排好的牌时,那么这些牌也跟着一起移动,游戏的目的是将所有的牌按同一花色从小到大排好,为了简单起见,我们的游戏只有同一花色的10张牌,从A到10,且随机的在一行上展开,编号从1到10,把第i号上的牌移到第j号牌上,移动距离为abs(i-j),现在你要做的是求出完成游戏的最小移动距离.   Input 第一个输入数据是…
上一次基本了解了下BFS,这次又找了个基本的DFS题目来试试水,DFS举个例子来说就是 一种从树的最左端开始一直搜索到最底端,然后回到原端再搜索另一个位置到最底端,也就是称为深度搜索的DFS--depth first search,话不多说,直接上题了解: Description:某石油勘探公司正在按计划勘探地下油田资源,工作在一片长方形的地域中.他们首先将该地域划分为许多小正方形区域,然后使用探测设备分别探测每一块小正方形区域内是否有油.若在一块小正方形区域中探测到有油,则标记为’@’,否则标…
#include<bits/stdc++.h>using namespace std;int n,m,k,l;int x[1007],y[1007],z[1007];int dp[1007][207];void init()//预处理n次处理后的情况{    for(int i=0;i<=l+100;i++)        dp[n+1][i]=-1;    for(int i=l+101;i<k+100;i++)        dp[n+1][i]=0;    for(int i…
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL. Initially, al…
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. Hide Tags Tree Depth-first Search  …
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. Hide Tags Depth-first Search Linked List       这题是将链表变成二叉树,比较麻烦的遍历过程,因为链表的限制,所以深度搜索的顺序恰巧是链表的顺序,通过设置好递归函数的参数,可以在深度搜索时候便可以遍历了.   TreeNode * he…
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Hide Tags Tree Depth-first Search     简单的深度搜索 #include <iostream> using namespace std; /*…