POJ -3050 Hopscotch
http://poj.org/problem?id=3050
给定一个5×5矩阵,问选6个数的不同排列总数是多少!
二维的搜索,注意要判重,数据量很小,直接用map就好。
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<map>
using namespace std; map<string,int>m;
int f[][],ans;
int dir[][]={-,,,,,,,-}; void dfs(int x,int y,int num,string s)
{
if(num==)
{
if(m[s]==)
{
//cout<<s<<endl;
m[s]++;
ans++;
}
return;
}
for(int i=;i<;i++)
{
int xx=x+dir[i][];
int yy=y+dir[i][];
if(xx>=&&xx<&&yy>=&&yy<)
{
string str = s;
s+=f[xx][yy]+'';
dfs(xx,yy,num+,s);
s=str; //这里需要回溯
}
}
}
int main()
{
//freopen("a.txt","r",stdin);
for(int i=;i<;i++)
for(int j=;j<;j++) scanf("%d",&f[i][j]);
ans=;
for(int i=;i<;i++)
for(int j=;j<;j++) dfs(i,j,,"");
printf("%d\n",ans);
return ;
}
POJ -3050 Hopscotch的更多相关文章
- POJ 3050 Hopscotch【DFS带回溯】
POJ 3050 题意: 1.5*5的方阵中,随意挑一格,记住这个格子的数字 2.可以上下左右走,走5次,每走一次记录下所走格子的数字 3.经过以上步骤,把所得6个数字连起来,形成一串数字.求共可以形 ...
- POJ 3050 Hopscotch 水~
http://poj.org/problem?id=3050 题目大意: 在一个5*5的格子中走,每一个格子有个数值,每次能够往上下左右走一格,问走了5次后得到的6个数的序列一共同拥有多少种?(一開始 ...
- POJ 3050 Hopscotch DFS
The cows play the child's game of hopscotch in a non-traditional way. Instead of a linear set of num ...
- poj 3050 Hopscotch DFS+暴力搜索+set容器
Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2774 Accepted: 1940 Description ...
- POJ 3050 Hopscotch 四方向搜索
Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6761 Accepted: 4354 Descrip ...
- POJ 3050 Hopscotch(dfs,stl)
用stack保存数字,set判重.dfs一遍就好.(或者编码成int,快排+unique #include<cstdio> #include<iostream> #includ ...
- Hopscotch(POJ 3050 DFS)
Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2845 Accepted: 1995 Descrip ...
- 【POJ - 3050】Hopscotch (dfs+回溯)
-->Hopscotch 这接写中文了 Descriptions: 奶牛们以一种独特的方式玩孩子们的跳房子游戏. 奶牛们创造了一个5x5的格子 他们熟练地跳上其中的一个格子,可以前后左右地跳(不 ...
- POJ 3050:Hopscotch
Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2506 Accepted: 1784 Descrip ...
随机推荐
- bzoj 2002 LCT
LCT最基础的题,就用到了一个ACCESS操作 首先我们将这个绵羊弹飞的情况看成一颗树,那么假设X点被弹飞到 Y点,那么Y为X的父亲节点,弹飞的话父亲节点为n+1(虚设) 那么每个询问就是询问X点到根 ...
- Matlab计算矩阵和函数梯度
一.差分与微分 我自己的理解. 二.求解 2.1 矩阵 这就是matlab的计算结果.太小的话放大些: c = 4 5 9 7 2 1 5 2 6 >> [x,y]=gradient(c) ...
- C#指针与字节数组的操作
private static byte[] ReadBytesFromPtr(IntPtr intPtr, int bufferLength) { var result = new byte[buff ...
- Codeforce 438D-The Child and Sequence 分类: Brush Mode 2014-10-06 20:20 102人阅读 评论(0) 收藏
D. The Child and Sequence time limit per test 4 seconds memory limit per test 256 megabytes input st ...
- 关灯问题 dp
题意是一排路灯,每个路灯有耗电量,照明度,需要给这n个路灯按顺序分组,每组内的最大耗电量是电灯数乘t,可以选择关闭一些电灯,求最大的照明度: 这题思路很明显,预处理出一个g[i][j]表示i到j分为一 ...
- javascript刷新页面的方法
Javascript刷新页面的几种方法: 1 history.go(0) 2 location.reload() 3 location=location 4 location.assign(locat ...
- Yarn的服务库和事件库
对于生命周期较长的对象,YARN采用了基于服务对象管理模型对其进行管理. 该模型有一下特点: 每个被服务化的对象都分为4个状态 任何服务状态变化都可以触发另外一些动作 可以通过组合方式对任意服务进行组 ...
- webvector将html转为svg或者png图片的工具
有些js较多,html组织不好的页面转换起来很不理想,cnblog转换的还不错 http://cssbox.sourceforge.net/webvector/
- Sqli-labs less 31
Less-31 Less-31与上述两个例子的方式是一样的,我们直接看到less-31的sql语句: 所以payload为: http://127.0.0.1:8080/sqli-labs/Less- ...
- appium获取android app的包名和主Activity
方法一在appium的android setting中选择下载到电脑上的app包,获取Activity. 方法二在android-sdk中安装build-tools包,进入这个目录.aapt dump ...