POJ 题目 Hopscotch(dfs)
来源:互联网 发布:java发起get请求 编辑:程序博客网 时间:2024/05/19 16:06
Hopscotch
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 2147 Accepted: 1542
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.
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 11 1 1 1 11 1 1 1 11 1 1 2 11 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.
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
USACO 2005 November Bronze
比赛时题目都没理解,,,,真的只想弱弱的说一句真的不会做搜索题~
ac代码
#include<stdio.h>#include<string>#include<set>#include<iostream>using namespace std;int x[5]={0,1,0,-1};int y[5]={1,0,-1,0};int map[5][5];set<int>p;void dfs(int i,int j,int v,int num){int k;if(v==6){p.insert(num);return;}if(i<0||i>=5)return;if(j<0||j>=5)return;for(k=0;k<4;k++){dfs(i+x[k],j+y[k],v+1,num*10+map[i][j]);}}int main(){int i,j;for(i=0;i<5;i++){for(j=0;j<5;j++){scanf("%d",&map[i][j]);}}for(i=0;i<5;i++){for(j=0;j<5;j++){dfs(i,j,0,0);}}printf("%d\n",p.size());}
0 0
- POJ 题目 Hopscotch(dfs)
- POJ Hopscotch (DFS)
- POJ 3050 Hopscotch (dfs)
- POJ 3050 Hopscotch(DFS)
- POJ NO.3050 Hopscotch(DFS,set)
- POJ 3050:Hopscotch(dfs + set容器)
- poj 3050 Hopscotch(dfs暴力)
- POJ:3050 Hopscotch(DFS+set)
- poj 3050 Hopscotch DFS
- POJ 3050 Hopscotch DFS
- poj 3050 Hopscotch 【DFS】
- Hopscotch (poj 3050 dfs)
- Hopscotch - POJ 3050 DFS
- poj 3050 Hopscotch 【dfs】
- Poj 3050 Hopscotch【dfs】
- poj 3050 Hopscotch 【DFS 暴力】
- poj 3050 Hopscotch(暴力dfs)
- 【POJ 3050 Hopscotch】+ DFS + set
- Sencha Touch延迟加载模块中的小类提高程序进入每个模块时性能
- World Wind Java开发之六——解析shape文件
- NodeJS+Redis实现分布式Session方案
- 3进制数
- Qt中提高sqlite的读写速度
- POJ 题目 Hopscotch(dfs)
- split
- QComboBox之item行高设置
- 真想住在山里修行
- Android休眠唤醒机制简介(一)
- php 命名空间1
- Android延时执行的几种方法
- javamail示例
- 安装APK文件的错误码定义大全