题目描述
棋盘上AAA点有一个过河卒,需要走到目标BBB点。卒行走的规则:可以向下、或者向右。同时在棋盘上CCC点有一个对方的马,该马所在的点和所有跳跃一步可达的点称为对方马的控制点。因此称之为“马拦过河卒”。
棋盘用坐标表示,AAA点(0,0)(0, 0)(0,0)、BBB点(n,m)(n, m)(n,m)(nnn, mmm为不超过202020的整数),同样马的位置坐标是需要给出的。
现在要求你计算出卒从AAA点能够到达BBB点的路径的条数,假设马的位置是固定不动的,并不是卒走一步马走一步。
输入输出格式
输入格式:一行四个数据,分别表示BBB点坐标和马的坐标。
输出格式:一个数据,表示所有的路径条数。
输入输出样例
说明
结果可能很大!
一个人问我的,那我就干脆写上吧。。
直接无脑dfs40分,
考虑dp即可;
很容易想到 dp[ i ][ j ]=dp[ i-1 ][ j ]+dp[ i ][ j-1 ];
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#pragma GCC optimize(2)
//#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 700005
#define inf 0x3f3f3f3f
#define INF 9999999999
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
}
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; }
/*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/
ll qpow(ll a, ll b, ll c) {
ll ans = 1;
a = a % c;
while (b) {
if (b % 2)ans = ans * a%c;
b /= 2; a = a * a%c;
}
return ans;
}
int n, m;
int Map[100][100];
ll ans;
int dx[] = { 1,1,2,2,-1,-1,-2,-2 };
int dy[] = { 2,-2,1,-1,2,-2,1,-1 };
int ddx[] = { 1,0 };
int ddy[] = { 0,1 };
bool check(int x, int y) {
return (x >= 0 && x <= n&&y >= 0 && y <= m);
}
ll dp[100][100];
int main(){
//ios::sync_with_stdio(0);
rdint(n); rdint(m);
int x, y; rdint(x); rdint(y); Map[x][y] = 1;
for (int i = 0; i < 8; i++) {
int nx = x + dx[i], ny = y + dy[i];
if (nx >= 0 && nx <= n&&ny >= 0 && ny <= m)Map[nx][ny] = 1;
}
dp[0][0] = 0; dp[1][0] = 1; dp[0][1] = 1;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
if (Map[i][j])continue;
if (!Map[i][j + 1]) {
dp[i][j + 1] += dp[i][j];
}
if (!Map[i + 1][j]) {
dp[i + 1][j] += dp[i][j];
}
}
}
cout << dp[n][m] << endl;
return 0;
}