Enum:Hopscotch(POJ 3050)
题目大意:牛像我们一样跳格子,一个5*5的方格,方格有数字,给牛跳5次,可以组成一个6个数字组合字符串,请问能组合多少个字符串?
题目规模很小,暴力枚举,然后用map这个玩具来检测存不存在就可以了,水题
#include <iostream>
#include <functional>
#include <algorithm>
#include <string>
#include <map> using namespace std; static int matrix[][];//图
static int ans;
string s_tmp = "";
map<string, char>dp; void Search(const int, const int,const int); int main(void)
{
for (int i = ; i < ; i++)
for (int j = ; j < ; j++)
scanf("%d", &matrix[i][j]); for (int i = ; i < ; i++)
for (int j = ; j < ; j++)
Search(i, j, );
cout << ans << endl; return ;
} void Search(const int y, const int x,const int level)
{
if (level == )
{
if (dp.find(s_tmp) == dp.end())
{
dp[s_tmp] = ;
ans++;
}
}
else
{
s_tmp[level] = matrix[y][x] + '';
if (y - >= )
Search(y - , x, level + );
if (y + < )
Search(y + ,x, level + );
if (x - >= )
Search(y, x - , level + );
if (x + < )
Search(y, x + , level + );
}
}
这速度差不多了
Enum:Hopscotch(POJ 3050)的更多相关文章
- POJ 3050 Hopscotch【DFS带回溯】
POJ 3050 题意: 1.5*5的方阵中,随意挑一格,记住这个格子的数字 2.可以上下左右走,走5次,每走一次记录下所走格子的数字 3.经过以上步骤,把所得6个数字连起来,形成一串数字.求共可以形 ...
- E - River Hopscotch POJ - 3258(二分)
E - River Hopscotch POJ - 3258 Every year the cows hold an event featuring a peculiar version of hop ...
- POJ -3050 Hopscotch
http://poj.org/problem?id=3050 给定一个5×5矩阵,问选6个数的不同排列总数是多少! 二维的搜索,注意要判重,数据量很小,直接用map就好. #include<cs ...
- POJ 3050 Hopscotch 水~
http://poj.org/problem?id=3050 题目大意: 在一个5*5的格子中走,每一个格子有个数值,每次能够往上下左右走一格,问走了5次后得到的6个数的序列一共同拥有多少种?(一開始 ...
- Hopscotch(POJ 3050 DFS)
Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2845 Accepted: 1995 Descrip ...
- 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+回溯)
-->Hopscotch 这接写中文了 Descriptions: 奶牛们以一种独特的方式玩孩子们的跳房子游戏. 奶牛们创造了一个5x5的格子 他们熟练地跳上其中的一个格子,可以前后左右地跳(不 ...
- 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 ...
随机推荐
- maven加载spring包
<dependencies> <dependency> <groupId>org.springframework</groupId> <artif ...
- JAVA 中SQL字符动态拼接
select SYR,SFZMHM,CJRZH,XSZBH,HPHM,CLSBDH,FDJH,CLLX,ZDYZT,to_char(CCDJRQ,'YYYY-MM-DD') CCDJRQ from V ...
- Record is locked by another user --Oracle行锁解锁
Oracle修改表中记录时出现record is locked by another user的问题 在操作表时没有commit,导致表被锁,只要执行下面两行语句,就可以了将行锁解锁了. 1. ...
- (原)String类两种实例化的区别
String有两种实例化方式,一种是通过直接赋值的方式,另外一种是使用标准的new调用构造方法完成实例化. public class StringDemo { public static void m ...
- POJ3744Scout YYF I(求概率 + 矩阵快速幂)
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6757 Accepted: 1960 Descr ...
- input type="submit" 和"button"有什么区别?
http://www.zhihu.com/question/20839977 在一个页面上画一个按钮,有四种办法: <input type="button" /> 这就 ...
- Spring学习4-面向切面(AOP)之Spring接口方式
一.初识AOP 关于AOP的学习可以参看帮助文档:spring-3.2.0.M2\docs\reference\html目录下index.html的相关章节 1.AOP:Aspect ...
- Python socket编程之六:多窗口的应用
import struct import sqlalchemy import pandas import matplotlib.pyplot as Plot from matplotlib.finan ...
- C语言产生随机数
rand产生随机数 #include"stdio.h" #include"stdlib.h" void main() { int i; for(i=0;i< ...
- [整] JavaScript m选n组合算法
01转换法: 思路是开一个数组,其下标表示1到m个数,数组元素的值为1表示其下标代表的数被选中,为0则没选中. 首先初始化,将数组前n个元素置1,表示第一个组合为前n个数. 然后从左到右扫描数组元素值 ...