LETTERS(搜索题)

LETTERS
Time Limit:1000MS    Memory Limit:10000KB    64bit IO Format:%I64d & %I64u

Description

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.

Input

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.

Output

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

Sample Input

3 6
HFDFFB
AJHGDH
DGAGEH

Sample Output

6

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int r, c, ans;
const int move[4][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
bool VisLetter[26], VisPos[21][21];
char board[21][21];

bool Judge(int i, int j)
{
    return (!VisLetter[board[i][j] - 'A'] && !VisPos[i][j] && i >= 0 && i < r && j >= 0 && j < c);
}

void DFS(int i, int j, int cnt)
{
    VisLetter[board[i][j] - 'A'] = VisPos[i][j] = 1;
    for(int k = 0; k < 4; k++)
    {
        int ii = i + move[k][0];
        int jj = j + move[k][1];
        if(Judge(ii, jj))
        {
            DFS(ii, jj, cnt + 1);
            VisLetter[board[ii][jj] - 'A'] = VisPos[ii][jj] = 0;
        }
    }
    if(ans < cnt) ans = cnt;
}

int main()
{
    while(scanf("%d %d", &r, &c) != EOF)
    {
        ans = 1;
        for(int i = 0; i < r; i++)
            scanf("%s", board[i]);
        memset(VisLetter, 0, sizeof(VisLetter));
        memset(VisPos, 0, sizeof(VisPos));
        DFS(0, 0, 1);
        printf("%d\n", ans);
    }
}


经过分析,当前提供的引用并未直接涉及 **CCF CSP 第四次认证第一** 的具体目解析或答案。然而,可以从已知的其他 CSP 认证目中推测可能的考察方向以及类似的解法。 以下是基于已有信息和专业知识的回答: --- ### CCF CSP 考核特点概述 CCF CSP 认证通常会设计一些基础编程问作为第一,这些问往往围绕字符串处理、简单数据结构操作或者基本算法展开[^1]。因此,在缺乏明确第四次认证第一具体内容的情况下,可以通过类比其他认证中的典型目来探讨其可能的形式与解答方法。 #### 可能形式之一:密码安全等级判断 如果参考 CCFCSP 第35次认证第一关于密码强度评估的内容,则该类型的目可能会要求选手编写程序依据特定规则判定一组给定密码分别属于哪一种安全性类别 (如样例所示分别为0, 1 和2)[^1] 。解决此类问的关键在于理解并实现评分标准逻辑,比如检查长度、字符多样性等因素。 ```cpp #include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; while(n--){ string s;cin>>s; bool hasUpper=false,hasLower=false,digit=false,specialChar=true; for(auto &c:s){ if(isupper(c))hasUpper=true; else if(islower(c))hasLower=true; else if(isdigit(c))digit=true; else specialChar=false;//assuming only letters and digits are allowed as per sample input/output. } if(hasUpper && hasLower && digit &&specialChar ) cout<<2<<"\n"; else if((hasUpper || hasLower)&&digit&&specialChar)cout<<1<<"\n"; else cout<<0<<"\n"; } } ``` 上述代码片段展示了如何通过遍历字符串中的每一个字符去检测是否存在大写字母、小写字母、数字以及其他特殊符号,并据此分配相应的分数。 #### 可能形式之二:序列查找 另一种常见模式体现在引用[2]所提到的商品价格区间匹配上。这类问一般需要参赛者能够快速定位满足条件的数据项位置或是统计符合条件的数量等基本信息[^2]。这背后涉及到的知识点包括但不限于数组索引访问、循环控制语句的应用等方面的基础技能训练。 对于这种类型的问解决方案可以采用简单的线性扫描方式完成初步筛选工作然后再进一步优化效率更高的搜索策略例如折半查找等等取决于实际需求场景下的性能考量因素不同而有所差异。 --- 尽管目前无法确切得知具体的试原文及其官方标准答案,但从历年真来看,无论是针对单一对象属性多维度综合评价还是集合内部成员间关系探索都构成了非常重要的命角度值得深入研究学习掌握其中蕴含的核心思想技巧以便从容应对未来可能出现的各种挑战情境之中脱颖而出成为佼佼者。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值