较为玄学的问题
查看原帖
较为玄学的问题
245875
Ame__楼主2020/7/7 07:34

此题在第一遍打完之后尝试再打一次加深印象,但是却因为开数组时位置不一样导致了RE,想请问原因,以下为代码

AC代码

#include<bits/stdc++.h>
 
#define LL long long
 
#define debug cerr << __LINE__ << " " << __FUNCTION__ << "\n" 

using namespace std;
 
template <typename T> void read(T & t) {              
    t = 0;int f = 1;char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-')f =- 1;ch = getchar();}
    do{t = t * 10 + ch - '0';ch = getchar();}while(ch >= '0' && ch <= '9');t *= f;
}

int n , m , t , r1 , c1 , r2 , c2;

char yoni[101][101];

int fx[5] , fy[5];

int dp[101][101][101] , judge[101][101];

int main(){
	read(n);read(m);read(t);
	for(int i = 1;i <= n;i ++){
		scanf("%s" , yoni[i] + 1);
	}
	/*for(int i = 1;i <= n;i ++){
		for(int j = 1;j <= m;j ++){
			scanf("%s" , yoni[i][j]);
		}
	}*/
	for(int i = 1;i <= n;i ++){
		for(int j = 1;j <= m;j ++){
			if(yoni[i][j] == '*'){
				judge[i][j] = 1;
			}
		}
	}
	read(r1);read(c1);read(r2);read(c2);
	fx[1] = 0 , fx[2] = 0 , fx[3] = 1 , fx[4] = -1;
	fy[1] = 1 , fy[2] = -1 , fy[3] = 0 , fy[4] = 0;
	dp[r1][c1][0] = 1;
	for(int k = 1;k <= t;k ++){
		for(int i = 1;i <= n;i ++){
			for(int j = 1;j <= m;j ++){
				for(int sora = 1;sora <= 4;sora ++){
					if(!judge[i + fx[sora]][j + fy[sora]]){
						dp[i][j][k] += dp[i + fx[sora]][j + fy[sora]][k - 1];
					}
				}
			}
		}
	}
	printf("%d" , dp[r2][c2][t]);
	return 0;
}

RE一点的代码

#include<bits/stdc++.h>
 
#define LL long long
 
#define debug cerr << __LINE__ << " " << __FUNCTION__ << "\n" 

using namespace std;
 
template <typename T> void read(T & t) {              
    t = 0;int f = 1;char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-')f =- 1;ch = getchar();}
    do{t = t * 10 + ch - '0';ch = getchar();}while(ch >= '0' && ch <= '9');t *= f;
} 

int n , m , t , r1 , c1 , r2 , c2;

char yoni[101][101];

int fx[5] , fy[5];

int judge[101][101] , dp[101][101][101];

int main(){
	read(n);read(m);read(t);
	for(int i = 1;i <= n;i ++){
		scanf("%s" , yoni[i] + 1);
	}
	for(int i = 1;i <= n;i ++){
		for(int j = 1;j <= m;j ++){
			if(yoni[i][j] == '*'){
				judge[i][j] = 1;
			}	
		}
	}
	read(r1);read(c1);read(r2);read(c2);
	fx[1] = 0 , fx[2] = 0 , fx[3] = 1 , fx[4] = -1;
	fy[1] = 1 , fy[2] = -1 , fy[3] = 0 , fy[4] = 0;
	dp[r1][c1][0] = 1; 
	for(int k = 1;k <= t;k ++){
		for(int i = 1;i <= n;i ++){
			for(int j = 1;j <= m;j ++){
				for(int sora = 1;sora <= 4;sora ++){
					if(!judge[i + fx[sora]][j + fy[sora]]){
						dp[i][j][k] += dp[i + fx[sora]][j + fy[sora]][k - 1];
					}
				}
			}
		}
	}
	printf("%d" , dp[r2][c2][t]);
	return 0;
}

RE一点的代码在更换数组judge与yoni位置之后便可通过

2020/7/7 07:34
加载中...