Enum:Hopscotch(POJ 3050)
2015-10-10 15:10
288 查看
跳格子
题目大意:牛像我们一样跳格子,一个5*5的方格,方格有数字,给牛跳5次,可以组成一个6个数字组合字符串,请问能组合多少个字符串?
题目规模很小,暴力枚举,然后用map这个玩具来检测存不存在就可以了,水题
#include <iostream> #include <functional> #include <algorithm> #include <string> #include <map> using namespace std; static int matrix[5][5];//图 static int ans; string s_tmp = "000000"; map<string, char>dp; void Search(const int, const int,const int); int main(void) { for (int i = 0; i < 5; i++) for (int j = 0; j < 5; j++) scanf("%d", &matrix[i][j]); for (int i = 0; i < 5; i++) for (int j = 0; j < 5; j++) Search(i, j, 0); cout << ans << endl; return 0; } void Search(const int y, const int x,const int level) { if (level == 6) { if (dp.find(s_tmp) == dp.end()) { dp[s_tmp] = 1; ans++; } } else { s_tmp[level] = matrix[y][x] + '0'; if (y - 1 >= 0) Search(y - 1, x, level + 1); if (y + 1 < 5) Search(y + 1,x, level + 1); if (x - 1 >= 0) Search(y, x - 1, level + 1); if (x + 1 < 5) Search(y, x + 1, level + 1); } }
这速度差不多了
相关文章推荐
- Linux守护进程的编程实现
- linux 终端的几个概念
- shell脚本格式化文件
- Hadoop常用命令
- Linux unison+inotify 文件实时双向同步
- linux命令行日志输出
- yum简单安装apache
- yum简单安装apache
- linux输入子系统(5) - 学习框架
- Linux命令总结【待续】
- Linux命令总结【待续】
- 将tomcat作成系统自启动服务并增大jvm启动内存
- linux无锁化编程--__sync_fetch_and_add系列原子操作函数
- linux 输入子系统(4) intput_dev 接口描述
- Linux下基于bitnami的Redmine安装部署以及结合Subversion的设置
- 《大型网站技术架构核心原理与案例分析读书笔记》
- 基于fl2440 内核linux3.0添加dm9000支持
- Apache与Tomcat 区别联系
- linux 输入子系统(3) button platform driver
- linux/centos安装nginx常见错误及解决办法【make错误,需要yum -y install openssl openssl-devel或者自己下载然后重新./configure】