A--LETTERS
来源:互联网 发布:爱知日语价格 编辑:程序博客网 时间:2024/05/20 09:09
/*poj 1154 dfs*/
题目大意为一个R行C列内容为大写英文字母的数组,求从数组(0,0)的位置开始能够走的最远的距离,所走的字母不能重复。
首先先设置一个flag[27]数组标示英文字母的状态(是否走过),其它就是dfs的步骤
#include<iostream>#include<stdio.h>#include<string.h>using namespace std;int r,c;char s[25][25];int flag[27];int ans;int map[4][2]={0,-1,0,1,-1,0,1,0};//方向数组void dfs(int x,int y,int n){ int i=0; for(i=0;i<4;i++) { int xx=x+map[i][0]; int yy=y+map[i][1]; if(xx>=0&&xx<r&&yy>=0&&yy<c&&!flag[s[xx][yy]-'A']) { flag[s[xx][yy]-'A']=1;//如果符合条件,将字母设为1,标志走过 dfs(xx,yy,n+1); } } if(n>ans) ans=n; flag[s[x][y]-'A']=0;//回溯的时候把状态数组恢复}int main(){ scanf("%d %d",&r,&c); memset(flag,0,sizeof(flag)); ans=0; for(int i=0;i<r;i++) { scanf("%s",s[i]); } flag[s[0][0]-'A']=1; dfs(0,0,1); printf("%d\n",ans); return 0;}
0 0
- A--LETTERS
- A. Anton and Letters
- A. Letters Cyclic Shift
- 443A - Anton and Letters
- LETTERS
- [PYthon] reverse letters in a string
- Codeforces 443A Anton and Letters(水题)
- CodeForces 443A Anton and Letters
- CodeForces 443A Anton and Letters
- CF 253A. Anton and Letters
- codeforces 708A - Letters Cyclic Shift
- CodeForces A. Letters Cyclic Shift【字符串】
- Codeforces Round #253 (Div. 2)A. Anton and Letters
- Codeforces Round #253 (Div. 2) A. Anton and Letters
- Codeforces Problem 708A Letters Cyclic Shift(implementation)
- CodeForces 708A. Letters Cyclic Shift (字符串处理,贪心)
- codeforces——443A——Anton and Letters
- Java中有int[26] for Letters ‘a’
- 嵌入式开发之C语言基础第三天&第四天学习笔记
- android的dmtracedump工具生成trace文件图片 'dot' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
- 1002 Matlab-imimposemin函数
- SSM搭建-Maven创建第一个web项目(22-2)servlet演示
- 在链串中,设计一个算法把最先出现的子串"ab"改为"xyz"
- A--LETTERS
- Linux 文件IO
- 【J2SE】认识变量
- 编程时避免使用 if 语句的五种模式
- 基于OpenCV调整图像的对比度和亮度
- linux 线程
- [普及] NOIP 2012 文化之旅
- 抗拒黄泉
- 《代码之髓》读书笔记之二:语法