40pts求助,wa
查看原帖
40pts求助,wa
313137
qqqqq111楼主2022/7/23 09:59
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>

namespace IO {
	typedef long long ll;
	inline ll rad() {
		int f=1;
		char c=getchar();
		ll x=0;
		while(c<'0' || c>'9') {
			if(c=='-')
				f=-1;
			c=getchar();
		}
		while(c>='0' && c<='9') {
			x=(x<<1)+(x<<3)+(c^48);
			c=getchar();
		}
		return x*f;
	}
	inline void print(ll x, char c='\n') {
		if(x) {
			if(x<0) {
				putchar('-');
				x=-x;
			}
			char bit[30];
			short l=0;
			while(x)
				bit[l++]=x%10^48, x/=10;
			for(l--; l>=0; l--) 
				putchar(bit[l]);
		}
		else
			putchar('0');
		putchar(c);
	}
}

using namespace IO;

const int N=1e2+5;
int n, m, dp;
std::string str[N];
struct node {
	int x, y;
};
node s, t;
int mx[5]={0, 1, 0, -1};
int my[5]={1, 0, -1, 0};
int vis[N][N];
int ans;

void dfs(node x, int dep) {
	if(dep>dp)
		return ;
	if(x.x==t.x && x.y==t.y && dep==dp) {
		ans++;
		return ;
	}
	for(int i=0; i<4; i++) {
		int nx=x.x+mx[i], ny=x.y+my[i];
		if(nx>=0 && nx<n && ny>=0 && ny<m && !vis[nx][ny] && str[nx][ny]!='*') {
			vis[nx][ny]=1;
			node ne=(node){nx, ny};
			dfs(ne, dep+1);
			vis[nx][ny]=0;
		}
	}
}

int main() {
	n=rad(), m=rad(), dp=rad();
	for(int i=0; i<n; i++)
		getline(std::cin, str[i]);
	s=(node){rad()-1, rad()-1};
	t=(node){rad()-1, rad()-1};
	dfs(s, 0);
	print(ans);
	return 0;
}
2022/7/23 09:59
加载中...