60分求助 中间两个不是TLE 是WA 跪求大佬相助
查看原帖
60分求助 中间两个不是TLE 是WA 跪求大佬相助
483607
Sui_da_xia隋顺意楼主2021/8/22 21:48
#include <bits/stdc++.h>
using namespace std;
long long n,m,ma_x,ma_y;
long long chess[22][22];
bool right(long long x,long long y){
	if (x > n || x < 0 || y > m || y < 0){
		return false;
	}
	return true;
}
void print_chess(){
	for (long long x=0;x<=n;x++){
		for (long long y = 0;y<=m;y++){
			cout << setw(9) <<  chess[x][y];
			cout << " ";
		}
		cout << endl;
	}
	cout << endl;
}
int main(){
	cin >> n >> m >> ma_x >> ma_y;
	long long i =0,j=0;
	for (i =0;i<=n;i++){
		for (j =0;j<=m;j++){
			chess[i][j] = 0;
		}
	}
	if (right(ma_x - 2,ma_y+1)){
		chess[ma_x - 2][ma_y+1] = -1;
	}
	if (right(ma_x-2,ma_y-1)){
		chess[ma_x - 2][ma_y-1] = -1;
	} if (right(ma_x-1,ma_y+2)){
		chess[ma_x - 1][ma_y+2] = -1;
	} if (right(ma_x-1,ma_y-2)){
		chess[ma_x - 1][ma_y-2] = -1;
	} if (right(ma_x + 2,ma_y+1)){
		chess[ma_x + 2][ma_y+1] = -1;
	} if (right(ma_x+2,ma_y-1)){
		chess[ma_x + 2][ma_y-1] = -1;
	} if (right(ma_x+1,ma_y+2)){
		chess[ma_x + 1][ma_y+2] = -1;
	} if (right(ma_x+1,ma_y-2)){
		chess[ma_x+1][ma_y-2] = -1;
	}
	chess[ma_x][ma_y] = -1;
	for (i = 0;i<=m;i++){
		if (chess[0][i] != -1){
			chess[0][i] = 1;
		}
	}
	for (j = 0;j<=n;j++){
		if (chess[j][0] != -1){
			chess[j][0] = 1;
		}
	}
	for (long long x = 1;x<=n;x++){
		for (long long y = 1;y <= m;y++){
			if (chess[x][y] == -1){
				continue;
			}
			if (chess[x][y-1] == -1){
				if (chess[x-1][y] == -1){
					chess[x][y] = 0;
				} else{
					chess[x][y] = chess[x-1][y];
				}
			} else{
				if (chess[x-1][y] == -1){
					chess[x][y] = chess[x][y-1];
				} else{
					chess[x][y] = chess[x][y-1] + chess[x-1][y];
				}
			}
		}
	}
	cout << chess[n][m] << endl;
}
2021/8/22 21:48
加载中...