Hopscotch
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2113   Accepted: 1514

Description

The cows play the child's game of hopscotch in a non-traditional way. Instead of a linear set of numbered boxes into which to hop, the cows create a 5x5 rectilinear grid of digits parallel to the x and y axes. 



They then adroitly hop onto any digit in the grid and hop forward, backward, right, or left (never diagonally) to another digit in the grid. They hop again (same rules) to a digit (potentially a digit already visited). 



With a total of five intra-grid hops, their hops create a six-digit integer (which might have leading zeroes like 000201). 



Determine the count of the number of distinct integers that can be created in this manner.

Input

* Lines 1..5: The grid, five integers per line

Output

* Line 1: The number of distinct integers that can be constructed

Sample Input

1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 2 1
1 1 1 1 1

Sample Output

15

Hint

OUTPUT DETAILS: 

111111, 111112, 111121, 111211, 111212, 112111, 112121, 121111, 121112, 121211, 121212, 211111, 211121, 212111, and 212121 can be constructed. No other values are possible.

Source

暴搜。水题..

#include <stdio.h>
#include <string.h>
#include <map> int G[5][5], ans;
const int mov[][2] = {0, 1, 0, -1, 1, 0, -1, 0};
std::map<int, int> mp; void DFS(int x, int y, int k, int sum) {
if(k == 6) {
if(mp[sum]++ == 0) ++ans;
return;
}
for(int i = 0, a, b; i < 4; ++i) {
a = x+mov[i][0];
b = y+mov[i][1];
if(a>=0&&b>=0&&a<5&&b<5)
DFS(a, b, k+1, sum*10+G[x][y]);
}
} int main() {
int i, j;
for(i = 0; i < 5; ++i)
for(j = 0; j < 5; ++j)
scanf("%d", &G[i][j]);
for(i = 0; i < 5; ++i)
for(j = 0; j < 5; ++j)
DFS(i, j, 0, 0);
printf("%d\n", ans);
return 0;
}

版权声明:本文博主原创文章。博客,未经同意不得转载。

POJ3050 Hopscotch 【DFS】的更多相关文章

  1. 【第40套模拟题】【noip2011_mayan】解题报告【map】【数论】【dfs】

    目录:1.潜伏者 [map] 2.Hankson的趣味题[数论]3.mayan游戏[dfs] 题目: 1. 潜伏者(spy.pas/c/cpp)[问题描述]R 国和S 国正陷入战火之中,双方都互派间谍 ...

  2. Kattis - glitchbot 【DFS】

    Kattis - glitchbot [DFS] 题意 有一个机器人 刚开始在(0, 0),然后给出一个目标点,并且会给出一系列指令,但是其中会有一个指令是错误的.我们需要找出那个指令,并且改成正确的 ...

  3. HDU 6113 度度熊的01世界 【DFS】(2017"百度之星"程序设计大赛 - 初赛(A))

    度度熊的01世界 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  4. 【dfs】P1331 海战

    题目描述 在峰会期间,武装部队得处于高度戒备.警察将监视每一条大街,军队将保卫建筑物,领空将布满了F-2003飞机.此外,巡洋船只和舰队将被派去保护海岸线.不幸的是因为种种原因,国防海军部仅有很少的几 ...

  5. 【dfs】p1731 生日蛋糕

    1441:[例题2]生日蛋搞 [题目描述] 7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆柱体.设从下往上数第i(1≤i≤M)层蛋糕是半径为Ri, 高 ...

  6. 【dfs】LETTERS

    1212:LETTERS [题目描述] 给出一个roe×colroe×col的大写字母矩阵,一开始的位置为左上角,你可以向上下左右四个方向移动,并且不能移向曾经经过的字母.问最多可以经过几个字母. [ ...

  7. 洛谷P1605 迷宫【dfs】

    题目背景 迷宫 [问题描述] 给定一个N*M方格的迷宫,迷宫里有T处障碍,障碍处不可通过.给定起点坐标和 终点坐标,问: 每个方格最多经过1次,有多少种从起点坐标到终点坐标的方案.在迷宫 中移动有上下 ...

  8. 【dfs】BZOJ1703-[Usaco2007 Mar]Ranking the Cows 奶牛排名

    [题目大意] 农夫约翰有N(1≤N≤1000)头奶牛,每一头奶牛都有一个确定的独一无二的正整数产奶率.约翰想要让这些奶牛按产奶率从高到低排序,约翰已经比较了M(1≤M≤10000)对奶牛的产奶率,但他 ...

  9. 【DFS】BZOJ3522-[Poi2014]Hotel

    [题目大意] 给出一棵树,求三个节点使得它们两两之间的距离相等,问共有多少种可能性? [思路] 显然,这三个节点是关于一个中心点对称地辐射出去的. 枚举中心点,往它的各个子树跑Dfs.tmp[i]表示 ...

随机推荐

  1. CF 552C 进制转换

    http://codeforces.com/problemset/problem/552/C C. Vanya and Scales time limit per test 1 second memo ...

  2. cPickle.so:: PyUnicodeUCS2_DecodeUTF8

    cPickle.so:: PyUnicodeUCS2_DecodeUTF8错误 Python编译的参数,和Python module(mod_wsgi, pymodwsgi)编译参数不一,导致一些un ...

  3. 重操JS旧业第一弹:Script与JS加载

    不管js被包装成什么样子,最终交给浏览器执行的js都是原生的,都离不开原生js的原理. Script标签纸html中用来加载js的标签,我们知道js可以是来自外部,本地,或者内部一段代码,在这里只讨论 ...

  4. delphi删除只读文件

    只读文件就是不能删除的文件,用DeleteFile函数对它来说是毫无意义的,要删除只读文件,只有先改变它的属性.如果你要删除一个文件,最好先作两个方面的考虑: (1)判断该文件的属性.可以用上面提到的 ...

  5. 博弈论之Nim

    博弈论(一):Nim游戏 重点结论:对于一个Nim游戏的局面(a1,a2,...,an),它是P-position当且仅当a1^a2^...^an=0,其中^表示位异或(xor)运算. Nim游戏是博 ...

  6. [置顶] ubuntu 和 win7 远程登陆 + vnc登陆

    ubuntu 和 win7 远程登陆: 第一种(通过win7自带的远程桌面来连接ubuntu) 1. windows7配置 我的电脑->属性->远程设置.-----允许远程连接 2. ub ...

  7. ALV预警灯图标代码

    需要先引用TYPE-POOLS: slis,icon. ICON_LED_GREEN 绿灯 ICON_LED_RED红灯 ICON_LED_YELLOW黄灯

  8. VC/MFC 在ListCtl 控件中随鼠标移动提示单元格信息

    BEGIN_MESSAGE_MAP(CTipListCtrl, CListCtrl) //{{AFX_MSG_MAP(CTipListCtrl) ON_WM_MOUSEMOVE() ON_WM_DES ...

  9. meminfo,df,

    yx100:root@yxRouter:/# cat /proc/meminfoMemTotal:         126584 kBMemFree:          103156 kBBuffer ...

  10. uva 10602 Editor Nottoobad(排序)

    题目连接:10602 Editor Nottoobad 题目大意:要输入n个单词,现在有三种操作, 1.输入一个字符,需要按下一次按键.  2.通过声控删除一个字符.3.通过声控复制一遍上面的单词.现 ...