大样例没过怎么还过了?
查看原帖
大样例没过怎么还过了?
935858
Bigtanks10楼主2024/10/26 16:55
#include<bits/stdc++.h>
using namespace std;
int t,n,m,x,y,k,ans,d,st[1010][1010];
int dx[5] = {0,1,0,-1},
	dy[5] = {1,0,-1,0};
char c[1010][1010];
void dfs(int x,int y,int cnt,int cx)
{
	if(cnt == k)
	{
		return ;
	}
	for(int i = 0;i <= 3;i++)
	{
		int cx1 = (cx + i) % 4,xx = x + dx[cx1],yy = y + dy[cx1];
		if(xx > 0 && xx <= n && yy > 0 && yy <= m && c[xx][yy] != 'x')
		{
			if(cnt + i + 1 > k)
			{
				break;
			}
			if(st[xx][yy] == 0)
			{
				ans++;
				st[xx][yy] = 1;
				dfs(xx,yy,cnt + i + 1,cx1);
				st[xx][yy] = 0;
			}
			else
			{
				dfs(xx,yy,cnt + i + 1,cx1);
				st[xx][yy] = 0;
			}
			break;
		} 
	}
}
int main()
{
	//freopen("explore5.in","r",stdin);
	//freopen("explore5.out","w",stdout);
	cin>>t;
	for(int i = 1;i <= t;i++)
	{
		ans = 1;
		cin>>n>>m>>k>>x>>y>>d;
		for(int j = 1;j <= n;j++)
		{
			for(int k1 = 1;k1 <= m;k1++)
			{
				cin>>c[j][k1];
			}
		}
		st[x][y] = 1;
		dfs(x,y,0,d);
		st[x][y] = 0;
		cout<<ans<<"\n";
	}
	return 0;
}

提交记录

2024/10/26 16:55
加载中...