标签:step == queue travel 输入 情况 mmap 题目 含义
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#define maxn 110
#define maxt 20
using namespace std;
const int dir[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
struct node{
int x, y, step;
node(){}
node(int _x, int _y, int _step){
x = _x, y = _y, step = _step;
}
};
queue<node> q;
bool mmap[maxn][maxn], vis[maxn][maxn][maxt];
int f[maxn][maxn][maxt];
int n, m, t;
int sx, sy, Tx, Ty;
bool check(const int &x, const int &y){
return 1 <= x && x <= n && 1 <= y && y <= m;
}
inline void bfs(){
q.push(node(sx, sy, 0));
f[sx][sy][0] = 1;
vis[sx][sy][0] = true;
while(q.size()){
node now = q.front();
q.pop();
if(now.step >= t) break;
int x = now.x, y = now.y;
for(register int i = 0; i < 4; i++){
int tx = x + dir[i][0];
int ty = y + dir[i][1];
if(mmap[tx][ty] || !check(tx, ty)) continue;
f[tx][ty][now.step + 1] += f[x][y][now.step];
if(!vis[tx][ty][now.step + 1]){
q.push(node(tx, ty, now.step + 1));
vis[tx][ty][now.step + 1] = true;
}
}
}
}
int main(){
scanf("%d %d %d", &n, &m, &t);
for(int i = 1; i <= n; i++){
getchar();
for(int j = 1; j <= m; j++){
mmap[i][j] = (getchar() == '.' ? false : true);
}
}
scanf("%d %d %d %d", &sx, &sy, &Tx, &Ty);
bfs();
printf("%d\n", f[Tx][Ty][t]);
return 0;
}
[Usaco2008 Mar]Cow Travelling游荡的奶牛
标签:step == queue travel 输入 情况 mmap 题目 含义
原文地址:https://www.cnblogs.com/akura/p/10853204.html