2.5基本算法之搜索 AK代码~+题解

该博客探讨了一款单人游戏的策略,游戏中棋子在RxC的板子上移动,目标是使棋子访问不同字母的位置数量最大化。输入描述了板子的尺寸和布局,输出为能访问的最大位置数。博主分享了解题思路,强调了搜索和回溯的重要性,并提供了递归解题的参考代码。
摘要由CSDN通过智能技术生成

2.5基本算法之搜索 156:LETTERS

总时间限制: 1000ms 内存限制: 65536kB

描述

A single-player game is played on a rectangular board divided in R rows and C columns. There is a single uppercase letter (A-Z) written in every position in the board.
Before the begging of the game there is a figure in the upper-left corner of the board (first row, first column). In every move, a player can move the figure to the one of the adjacent positions (up, down,left or right). Only constraint is that a figure cannot visit a position marked with the same letter twice.
The goal of the game is to play as many moves as possible.
Write a program that will calculate the maximal number of positions in the board the figure can visit in a single game.

输入

The first line of the input contains two integers R and C, separated by a single blank character, 1 <= R, S <= 20.
The following R lines contain S characters each. Each line represents one row in the board.

输出

The first and only line of the output should contain the maximal number of position in the board the figure can visit.

样例输入
3 6
HFDFFB
AJHGDH
DGAGEH

样例输出
6

来源
Croatia OI 2002 Regional Competition - Juniors

解题关键:
使用搜索与回溯,递归(自己调用自己)。

参考代码:

#include<iostream>
#include<cstdio>
using namespace std;
char a[21][21
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值