Biggest Number

时间限制:1000 ms  |  内存限制:65535 KB
难度:4
描述

You have a maze with obstacles and non-zero digits in it:

You can start from any square, walk in the
maze, and finally stop at some square. Each step, you
may only walk into one of the four neighbouring squares (up, down,
left, right)
and you cannot walk into
obstacles or walk into a square more
than once. When you finish, you can get a number by writing down the digits you
encounter in the same order as you meet them. For example, you can get numbers 9784, 4832145 etc. The biggest
number you can get is 791452384, shown in the picture above.

Your task is to find the biggest number you can
get.

输入
There will be at most 25 test cases. Each test begins with
two integers R and C (2<=R,C<=15, R*C<=30), the number of rows
and columns of the maze. The next R rows represent the maze. Each line
contains exactly C characters (without leading or trailing spaces), each
of them will be either '#' or one of the nine non-zero digits. There
will be at least one non-obstacle squares (i.e. squares with a non-zero
digit in it) in the maze. The input is terminated by a test case with
R=C=0, you should not process it.
输出
For each test case, print the biggest number you can find, on a single line.
样例输入
3 7
##9784#
##123##
##45###
0 0
样例输出
791452384
来源
湖南省第六届大学生计算机程序设计竞赛
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsgAAABmCAIAAABZQPCWAAAgAElEQVR4nO1d3Ysdx5Xf/6leLkyGYVi4DEJhbdoekGUUMGuQIXpwL2hwWKOsE7F2gtgGLax2RaIsZldrsY1jJ7bBEbGCo4DMjXEgSkiUh8EP87IMLPetccLuQ3/U+ayPvn3vjKTze7A193ZXnTp16pzfOdVd96/+V0JjMBgMBoPBEMT/SfgrIxYGg8FgMBhGwIiFwWAwGAyGyWDEwmAwGAwGw2QwYmEwGAwGg2EyGLEwGAwGg8EwGYxYGAwGg8FgmAxGLAwGg8FgMEwGIxYGg8FgMBgmgxELg8FgMBgMk8GIhcFgMBgMhslgxMJgMBgMBsNkMGLx1OLw/o//+xePTloKwxOJ//n1h+/87DfLkxbDYDCcBIxYPJ04rC/P5+WdRxt0/R995+ze3u6Wc865rd29vb29vd2t2fb83Ks3Pk6WY3n02e03L56bb8+2dvf2dnfPvFLdPTy8e3X/zBt31z6Ww/uf/OrL4/6v4y9/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BMg6+++sqIhcFgMBgMhmnwl7/8xYiFwWAwGAyGCfDnP/9ZZBVGLAwGg8FgMGTgq6++0moVHbEIfGcwGAwGg8GQBSMWBoPBYDAYJoMRC4PBYDAYDJPh/wFhf2kfn78tpgAAAABJRU5ErkJggg==" alt="" />
题解:非常巧妙地剪枝想法,每次DFS一个位置的时候,处理它能够到达的所有的点,我们假设这些点都是沿着它可以到达的,如果当前点的数量+当前的搜索长度<已经得到的最优解的长度,那么这段必定是可以减掉的,因为无论怎么走都达不到最优解的长度了.还有一种就是能够达到点的数量+当前的搜索长度 = 已经得到的最优解的长度,那么我们只要在当前搜索的解后面添一个最大的数字 '9',如果这样的结果字典序还比已经得到的最优解的字典序小,那么也没有搜索下去的必要了,直接剪枝,这里的BFS按照我的理解就相当于一个估价函数,让结果一直往正确的方向走.很厉害的题目。
还有一个小插曲:就是关于手动队列和STL自带队列,自带队列在某些时候要慎用,比如说这个题,BFS调用的次数比较多,给大家看一下两者的时间。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAeYAAACJCAMAAADOmGvGAAAAAXNSR0IArs4c6QAAALRQTFRF////+Pj45+fn///v6enp4+Pj4eHhAAAA7e3tq6urmZmZ9fX17+/v8/Pzz6uZvd/////f3///7////9+919fY29vcz+//mazP/+/Po6OjvZmZq8/vvb/BmJq9mb3f78+r372Zq5mrmZmrvZmrzc7RVJmLvZm9q5m98vPxaWxuz6us0MXBq5mZlLC1rKvPta2Z7Ovrx97hkpKSBOZHcJuvLyoyN6xZBO1KqMK/o1VWp5Zwr9W1Po5JDAAAB7FJREFUeNrtmotC2kgUhqegBREFRNEWBWrRhVpadNvdtvv+77XnzCWZG5NAIwr9fy9DJnM5M1/OmUmCeMM6Pj45mbXb7WazuaxIrSn9klpPc/q9qET/kpYX6meu0yVUQkJTnrUl4QNSrRK1prXWA6lKzH+TLmrqZ65TqIyEokyOvGS+h5XpaXr4dE16eprT73klYsyH5+pnrtNDqIQkZvLlo6o1b9EvaS71roR+fS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JpBeAQCYQHoFAGAC6RUAgAmkVwAAJnwcx3Ect3es3oEAALQWnyzLsjyz5adIsAAAXvITEVH3vqOv1TkQAIDWYhx7HXu8rc3v97e3t3d0PPGOUpZ+tX/9vveU15mfPXLrT2ZXMEQAgGbkqxx3HXvc973P9p8qFAr5fD53mL6/+sl36xccAEDz8s0cOLFD/W5r7FCsb/8bT3WX/vnQMy9s//lh5FcAAPd83fuOyvJoNLbD4rut7bd3m5YDAIAddey1b8ttRAM/iB57evcr5ZHVd178EQ0OhJSJz2fniIgy7/1qcsWjBABoVtFRWVEsvr1nuXj4l5cvLy0tLS4ufvL8PUrRtl27ttKjzx08WJ9AAQCaBCfLsnZarlTUkCRJkqR8Pp/L5SYmJnbu3FmvoAEAGh9uigUAYALpFQCACaRXAAAmkF4BAJj4fzCCpL2WmCNNAAAAAElFTkSuQmCC" alt="" />(STL自带)
一直超时找不到原因,改成手动队列跑得飞快,还有就是 string 类型也要谨慎使用,这些STL自带功能会消耗时间
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
using namespace std;
const int N = ;
int n,m,MAX;
char mp[N][N];
bool flag[N][N];
bool vis[N][N];
int dir[][] = {{,},{-,},{,-},{,}};
struct Node{
int x,y;
};
char res[N],ans[N],ans1[N];
bool check(int x,int y){
if(x<||x>n||y<||y>m||mp[x][y]=='#') return false;
return true;
}
Node q[N * N];
int bfs(int x,int y){
memset(flag,,sizeof(flag));
int head = , tail = ,ret = ;;
q[tail].x = x; ///手动队列非常快
q[tail++].y = y;
flag[x][y] = true;
while(head!= tail){
int nowx = q[head].x;
int nowy = q[head++].y;
for(int i=;i<;i++){
int nextx = nowx+dir[i][];
int nexty = nowy+dir[i][];
if(!check(nextx,nexty)||flag[nextx][nexty]||vis[nextx][nexty]) continue;
ret++;
flag[nextx][nexty] = true;
q[tail].x = nextx;
q[tail++].y = nexty;
}
}
return ret;
} void dfs(int x,int y,int step){
if(step>MAX||step==MAX&&strcmp(ans,res)>){
MAX = step;
strcpy(res,ans);
}
int GO = bfs(x,y); ///预处理最好的情况,所有点都可达
strcpy(ans1,ans);
ans1[step] = '';
if(GO+step<MAX||GO+step==MAX&&strcmp(ans1,res)<) return; ///剪枝,(x,y)能够走的距离 < 答案
for(int i=0;i<4;i++){
int nextx = x+dir[i][0];
int nexty = y+dir[i][];
if(!check(nextx,nexty)||vis[nextx][nexty]) continue;
vis[nextx][nexty] = true;
ans[step] = mp[nextx][nexty];
dfs(nextx,nexty,step+);
ans[step] = ;
vis[nextx][nexty] = false;
}
}
int main()
{
freopen("f.in","r",stdin);
freopen("f.txt","w",stdout);
while(scanf("%d%d",&n,&m)!=EOF,n+m){
int tot = ;
for(int i=;i<=n;i++){
scanf("%s",mp[i]+);
for(int j=;j<=m;j++){
if(mp[i][j]!='#') tot++;
}
}
memset(res,,sizeof(res));
MAX = -;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(mp[i][j]=='#'||MAX==tot&&mp[i][j]<res[]) continue;
memset(vis,false,sizeof(vis));
ans[] = mp[i][j];
vis[i][j] = true;
dfs(i,j,);
}
}
printf("%s\n",res);
}
return ;
}
/**
5 6
245356
342534
534635
423535
324345
*/

湖南省第六届省赛题 Biggest Number (dfs+bfs,好题)的更多相关文章

  1. UVA - 11882 Biggest Number(dfs+bfs+强剪枝)

    题目大意:给出一个方格矩阵,矩阵中有数字0~9,任选一个格子为起点,将走过的数字连起来构成一个数,找出最大的那个数,每个格子只能走一次. 题目分析:DFS.剪枝方案:在当前的处境下,找出所有还能到达的 ...

  2. 湖南省第六届大学生程序设计大赛原题 F Biggest Number (UVA1182)

    Biggest Number http://acm.hust.edu.cn/vjudge/contest/view.action?cid=30851#problem/F 解题思路:DFS(检索)+BF ...

  3. 湖南省第6届程序大赛第6题 Biggest Number

    Problem F Biggest Number You have a maze with obstacles and non-zero digits in it: You can start fro ...

  4. 山东省第六届省赛 H题:Square Number

    Description In mathematics, a square number is an integer that is the square of an integer. In other ...

  5. 蓝桥杯第六届省赛 手链样式 STL

    小明有3颗红珊瑚,4颗白珊瑚,5颗黄玛瑙.他想用它们串成一圈作为手链,送给女朋友.现在小明想知道:如果考虑手链可以随意转动或翻转,一共可以有多少不同的组合样式呢? 分析:这个题首先一定要理解题意,转动 ...

  6. 算法笔记_119:蓝桥杯第六届省赛(Java语言A组)试题解答

     目录 1 熊怪吃核桃 2 星系炸弹 3 九数分三组 4 循环节长度 5 打印菱形 6 加法变乘法 7 牌型种数 8 移动距离 9 垒骰子 10 灾后重建   前言:以下试题解答代码部分仅供参考,若有 ...

  7. 算法笔记_120:蓝桥杯第六届省赛(Java语言B组部分习题)试题解答

     目录 1 三角形面积 2 立方变自身 3 三羊献瑞 4 九数组分数 5 饮料换购 6 生命之树   前言:以下试题解答代码部分仅供参考,若有不当之处,还请路过的同学提醒一下~ 1 三角形面积 三角形 ...

  8. 地铁 Dijkstra(优先队列优化) 湖南省第12届省赛

    传送门:地铁 思路:拆点,最短路:拆点比较复杂,所以对边进行最短路,spfa会tle,所以改用Dijkstra(优先队列优化) 模板 /******************************** ...

  9. FZOJ--2221-- RunningMan 福建第六届省赛

    题目链接:http://acm.hust.edu.cn/vjudge/contest/127149#problem/J 题目大意: 因为总共就分三个队,因为两个队都要选取最优的策略,不论B队咋放,要使 ...

随机推荐

  1. 代码收藏系列--mysql--创建数据库、数据表、函数、存储过程命令

    创建mysql数据库 CREATE DATABASE IF NOT EXISTS `database_name` DEFAULT CHARSET utf8 COLLATE utf8_general_c ...

  2. Linux基础-shell脚本知识整理和脚本编写----------变量、运算符、流程控制、函数、计划任务(发送邮件)

    I:知识整理:变量.运算符.流程控制.函数.计划任务 变量 系统变量:set:显示所有变量                env:环境变量 常用系统变量: path pwd lang home his ...

  3. codeforces gym101243 A C D E F G H J

    gym101243 A #include<iostream> #include<cstdio> #include<cmath> #include<cstrin ...

  4. 手脱EZIP v1.0

    一.单步 1.载入PEID查壳 EZIP v1.0 2.载入OD,一上来就是一个大跳转,F8单步一直走 0040D0BE > $ /E9 jmp Notepad.004102DC ; //入口点 ...

  5. linux 版本查询

    原文 : http://www.ha97.com/2987.html 一.查看Linux内核版本命令(两种方法): 1.cat /proc/version [root@localhost ~]# ca ...

  6. 第2章-Vue.js指令

    一.学习目标 了解 什么 是 Vue.js 指令 理解 Vue.js 指令的 用途 掌握 Vue.js 指令的书写规范 能够 使用 Vue.js 指令完成部门页面交互效果(难点和重点) 二.指令的基本 ...

  7. Eclipse中使用Maven创建项目 (转)

    转自:http://www.gogogogo.me/development/eclipse-maven-webapp.html       Apache Maven是一个优秀的项目构建和管理工具,许多 ...

  8. 树形dp的进阶 (一)

    ①树的重心的性质的运用 ②缩点以后寻找规律  树的直径! ③树形dp上的公式转换 ④和期望有关的树形dp + 一点排列组合的知识 ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ 一:Codeforces Round #364 ...

  9. 原生JS实现省市区(县)三级联动选择

    原文地址→看过来 写在前面 前段时间写一个关于天气的东西,里面的省市区(县)城市选择让我很头疼,在网上搜索出来大都是借助插件或者第三方库,感觉这样做代码会很重,所以索性就把几种城市选择的方式实现一遍, ...

  10. FTP、SFTP文件下载内容校验

    描述: 从FTP.SFTP下载的文件做MD5码校验,文件名和MD5码值存放在表格里,表格位置在FTP.SFTP服务器上. os模块只能遍历本地目录/文件,需要先连接FTP.SFTP服务器,将表格下载到 ...