Hopscotch POJ
来源:互联网 发布:新代系统编程说明书 编辑:程序博客网 时间:2024/06/06 19:17
给出一个5*5的数组,问能组成多少个不重复的六位组合
参考别人的博客得出的思路,利用stl中set的去重性
#include <cstdio>#include <algorithm>#include <set>#include <string>using namespace std;int mp[10][10];int tx[4]={0,1,0,-1};int ty[4]={1,0,-1,0};string ss;set<string> s; void dfs(int x,int y,int c) {if (c==5) {s.insert(ss);return;}for (int i=0;i<4;i++) {int xx=x+tx[i];int yy=y+ty[i];if (xx<0 || yy<0 || xx>=5 || yy>=5) continue;ss.push_back(mp[xx][yy]+'0');dfs(xx,yy,c+1);ss.resize(ss.size()-1); //pop_back通不过c++的编译}return;}int main(){for (int i=0;i<5;i++) {for (int j=0;j<5;j++) scanf ("%d",&mp[i][j]);}for (int i=0;i<5;i++) {for (int j=0;j<5;j++) {ss=mp[i][j]+'0';dfs(i,j,0);}} printf ("%d\n",s.size());return 0; }
0 0
- Hopscotch POJ
- Hopscotch POJ
- poj 3258 River Hopscotch
- Dichotomy poj River Hopscotch
- poj-3258 River Hopscotch
- poj-3258 River Hopscotch
- poj 3258 River Hopscotch
- poj 3258 River Hopscotch
- POJ 3258 River Hopscotch
- POJ 3258 River Hopscotch
- poj 3258 River Hopscotch
- POJ-3258-River Hopscotch
- POJ 3050 Hopscotch
- POJ 3258 River Hopscotch
- poj 3050 Hopscotch DFS
- POJ 3258 River Hopscotch
- poj 3050 Hopscotch
- POJ-3050-Hopscotch
- 用jQuery Pagination插件实现的简易低效分页功能
- matplotlib绘图(极坐标 3D绘图等)(3)
- Apache Ignite
- css缩写代码大全
- 6种基础排序算法的理解(更新中)
- Hopscotch POJ
- poj 2524 普通并查集
- Java三大主流框架概述(转载)
- js原生Ajax 的封装和原理之浅析
- 2.1 矩阵定义
- USB Blaster 无法识别
- React Router 最新指南与异步加载实践
- 复杂网络的一些基本性质
- 算法与数据结构基础知识