思路很重要,从x1,y1到x2,y2.
八向;
问最短步数的路径有几条。
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
int now[5010],temp[5010];
int fun(int s,int r,int a,int b)
{
memset(now,0,sizeof(now));
memset(temp,0,sizeof(temp));
now[a]=1;
for (int i=0;i<s;i++)
{
for (int j=0;j<r;j++)
{
temp[j]=now[j];
if (j>0) temp[j]=(temp[j]+now[j-1])%5318008;
if (j<r-1) temp[j]=(temp[j]+now[j+1])%5318008;
}
for (int j=0;j<r;j++)
{
now[j]=temp[j]%5318008;
}
}
return now[b];
}
int main()
{
// #ifndef ONLINE_JUDGE
// freopen("in.txt","r",stdin);
// freopen("out.txt","r",stdout);
// #endif
int T;
scanf ("%d",&T);
while (T--)
{
int n,x1,y1,x2,y2;
scanf ("%d%d%d%d%d",&n,&x1,&y1,&x2,&y2);
int lx=abs(x2-x1),ly=abs(y2-y1);
if (lx>ly)printf ("%d\n",fun(lx,n,y1-1,y2-1));
else printf ("%d\n",fun(ly,n,x1-1,x2-1));
}
return 0;
}