求大佬帮调!
查看原帖
求大佬帮调!
654763
smallpeople楼主2024/6/18 20:34

蒟蒻的代码

#include<bits/stdc++.h>
using namespace std;

int n,m,T;
int r,c,rr,cc;
int a[105][105][50];
int fx[4][2] = {{-1,0},{1,0},{0,-1},{0,1}};
char p[105][105];

int dfs(int x,int y,int t)
{
	if(t > T)return 0;
	
	for(int i = 0;i < 4;i ++)
	{
		int nx = x + fx[i][0],ny = y + fx[i][1];
		if(nx < 1 || nx > n || ny < 1 || ny > m)continue;
		if(p[nx][ny] == '*')continue;
		
		a[nx][ny][t + 1] += a[x][y][t];
		dfs(nx,ny,t + 1);
	}
}

int main()
{
	cin>>n>>m>>T;
	for(int i = 1;i <= n;i ++)
		for(int j = 1;j <= m;j ++)
			cin>>p[i][j];
	cin>>r>>c>>rr>>cc;
	
	a[r][c][0] = 1;
	dfs(r,c,0);
	
	for(int k = 0;k <= T;k ++)
	{
		for(int i = 1;i <= n;i ++)
	{
		for(int j = 1;j <= m;j ++)
			cout<<a[i][j][k]<<" ";
		cout<<'\n';
	}
	cout<<'\n';
	}
	
	return 0;
}
/*
4 5 8
...*.
...*.
.....
.....
1 3 1 5
*/
2024/6/18 20:34
加载中...