POJ 1979 Red and Black
来源:互联网 发布:如何开淘宝实体店 编辑:程序博客网 时间:2024/05/29 19:54
题目:
大概意思是,在一个矩形房间里,有红色地砖和黑色地砖,一个人只能在黑色地砖走,红色不能走,给定一个起点,问最多能走多少步。
如:
1 0 1 0
1 1 1 0
0 1 0 1
1 0 0 0
1代表黑色,0代表红色,只能走黑色
从(0,0)开始,一共能走6个,所以输出6
#include<iostream>using namespace std;int mi[10][10];int d[4][2] = { {-1,0}, {1 ,0}, {0,-1}, {0,1} };int visit[5][5];void dfs(int sx, int sy,int mi[5][5],int &count){ visit[sx][sy] = 1; ++count; for (int i = 0; i < 4; i++) { int nx = sx + d[i][0]; int ny = sy + d[i][1]; if (nx >= 0 && nx < 5 && ny >= 0 && ny <5 && mi[nx][ny]==1 && visit[nx][ny]==0) { dfs(nx,ny,mi,count); } } return;}void solve(){ int count = 0; //int mi[4][4] = { {1,0,1,0},{1,1,0,0},{1,0,1,1},{1,1,1,1} }; //int mi[4][4] = { { 1,0,1,0 },{ 1,1,1,0 },{0,1,0,1 },{ 1,0,0,0 } }; int mi[5][5] = { {1,1,0,1,0},{1,0,1,1,0},{1,1,1,0,1},{0,0,1,0,1},{0,1,1,1,0} }; dfs(2, 4,mi,count); printf("能走:%d格", count); cout << endl;}int main(){ solve(); system("pause"); return 0;}
阅读全文
0 0
- POJ 1979 Red and Black
- poj 1979 Red and Black
- POJ 1979 - Red and Black
- POJ-1979-Red and Black
- poj 1979 red and black
- poj 1979 Red and Black
- poj 1979 Red and Black
- POJ:1979 Red and Black
- POJ 1979 - Red and Black
- POJ 1979 Red and Black
- POJ 1979 Red and Black
- POJ 1979 Red and Black
- poj 1979 Red and Black
- POJ 1979 Red and Black
- poj 1979Red and Black
- POJ 1979 Red and Black
- POJ 1979 Red and Black
- POJ 1979-Red and Black
- jquery $().each和$.each()使用
- JAVA课程3 输出100内的素素
- 计算机网络-6
- Xrecycleview的使用
- 欢迎使用CSDN-markdown编辑器
- POJ 1979 Red and Black
- WinForm Chart控件使用记录(由于制作饼装,柱状,折线图)
- bzoj 1426(期望dp)(公式推导)
- 免装版tomcat注册成windows系统服务方法
- 如何对HashMap按键值排序
- git链接远程仓库已经新建本地仓库
- 求当前数组中,最大值减最小值等于sum的数组个数
- bzoj4719: [Noip2016]天天爱跑步
- 接口练习