NOIP2002 Guohe Cu

NOIP2002 Guohe Cu

题目描述
棋盘上AA点有一个过河卒,需要走到目标BB点。卒行走的规则:可以向下、或者向右。
同时在棋盘上CC点有一个对方的马,该马所在的点和所有跳跃一步可达的点称为对方马
的控制点。因此称之为“马拦过河卒”。

棋盘用坐标表示,AA点(0, 0)(0,0)、BB点(n, m)(n,m)(nn, mm为不超过2020的整
数),同样马的位置坐标是需要给出的。


现在要求你计算出卒从AA点能够到达BB点的路径的条数,假设马的位置是固定不动的,
并不是卒走一步马走一步。

输入格式
一行四个数据,分别表示BB点坐标和马的坐标。

输出格式
一个数据,表示所有的路径条数。

输入输出样例
输入 #1
6 6 3 3
输出 #1
6
说明/提示
结果可能很大!

This is a simple DP problem
as long as the establishment of an array of coordinates, dx, dy
used to control the direction, very simple

#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
long long a[22][22],f[22][22];
int dx[8]={2,1,-1,-2,-2,-1, 1, 2};
int dy[8]={1,2,2 ,1, -1,-2,-2,-1};
int main()
{
	int i,n,j,m,x,y;
	cin>>n>>m>>x>>y;
	n++;m++;x++;y++;
	f[x][y]=-1;
	for(i=0;i<8;i++)
	{
		int xx,yy;
		xx=x+dx[i];
		yy=y+dy[i];
		if(xx>=1 and xx<=n)
		if(yy>=1 and yy<=m)
			f[xx][yy]=-1;
	}
	a[0][1]=1;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(f[i][j]!=-1)
			{
				a[i][j]=a[i-1][j]+a[i][j-1];
			}
			else
				a[i][j]=0;
		}
	}
	cout<<a[n][m];
	return 0;	
}
Published 37 original articles · won praise 31 · views 5965

Guess you like

Origin blog.csdn.net/user_qym/article/details/104087597