P1002 [NOIP2002 普及组] 过河卒

#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
typedef pair<int ,int > p;
typedef long long ll;

int xa,ya,xm,ym;
ll c[22][22];

int v[22][22];

int xx[8]={1,2,-1,2,1,-2,-1,-2};
int yy[8]={2,1,2,-1,-2,1,-2,-1};

int main()
{
   scanf("%d %d %d %d",&xa,&ya,&xm,&ym);
  v[xm][ym]=1;
   for(int i=0;i<8;i++)
   {
       int xxm=xm+xx[i];
       int yym=ym+yy[i];
       if(xxm>=0&&xxm<=xa&&yym>=0&&yym<=ya)
       v[xxm][yym]=1;
   }
   for(int i=0;i<=xa;i++)
    for(int j=0;j<=ya;j++)
   {
       if(!v[i][j])
        c[i][j]=1;
   }
    for(int i=0;i<=xa;i++)
    for(int j=0;j<=ya;j++)
    {  if(v[i][j])
       c[i][j]=0;
        else if(i==0&&j==0)
            ;
        else if(i==0)//处理边界
        {
     c[i][j]=c[i][j-1];

        }
        else if(j==0)
        {
            c[i][j]=c[i-1][j];
        }
        else
                 c[i][j]=c[i-1][j]+c[i][j-1];

    }


  printf("%lld\n",c[xa][ya]);
}

https://www.luogu.com.cn/problem/P1002

posted @ 2021-07-28 18:43  废柴废柴少女  阅读(92)  评论(0)    收藏  举报