大佬求救,0pts
查看原帖
大佬求救,0pts
1063799
chenshenqi楼主2024/3/21 20:58
#include <bits/stdc++.h>
using namespace std;
bool check(int x1,int y1,int x2,int y2,int n,int m){
	if (x1<1||y1<1||x1>n||y1>m){
		return false;
	}
	if (x1==x2-2&&y1==y2-1||x1==x2-2&&y1==y2+1||x1==x2+2&&y1==y2-1||x1==x2-2&&y1==y2+1||x1==x2-1&&y1==y2-2||x1==x2+1&&y1==y2-2||x1==x2-1&&y1==y2+2||x1==x2+1&&y1==y2+2||x1==x2&&y1==y2){
		return false;
	}
	return true;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int dp[x1+5][y1+5]={};
    for (int i=1; i<=x1; i++) dp[1][i]=1;
    for (int i=1; i<=x1; i++){
		for (int j=1; j<=y1; j++){
			if (!check(i,j,x2,y2,x1,y1)){
				if (!(i==1&&j==1)){
					dp[i][j]=0;
				}
				
			}else{
				dp[i][j]=dp[i][j-1]+dp[i-1][j]+dp[i][j];
			}
		}
	}
    cout << dp[x1][y1];
	return 0;
}

2024/3/21 20:58
加载中...