1314: [Example 3.6] Guohe Cu (Noip2002)

Portal:

 

 

Description [title]

A point on the board has a Guohe Cu, B needs to go to the target point. Death walking rules: can be down, or right. At the same time there is a certain point of the other horses (e.g. point C) on the board, the point where the horse jumps one step up and all the other point is called a control point of the horse, as shown in point C in P1 and 3-1 , ......, P8, and death can not control the other points of the horse. Chessboard coordinate representation, A point (0,0), B point (n, m) (n, m is an integer of not more than 20), the position coordinates of the same horse is given needs, C ≠ A and C ≠ B . Now you calculate the required number of paths can reach the stroke from point A to point B.

[Enter]

Coordinates are given n, m and the point C.

[Output]

From point A to reach the number of path B points.

[Sample input]

8 6 0 4

[Sample Output]

1617


#include<iostream>
#include<cstring>
using namespace std;
#define N 25
int l[]={1,1,-1,-1,2,2,-2,-2};
int o[]={2,-2,2,-2,1,-1,1,-1};
string dp[N],k[N];
int n,m,x1,y1;
bool no[N][N];
string g(string a,string b)
{
    string ans;
    int as[255]={0},bs[255]={0},cs[255]={0},len;
    memset(as,0,sizeof(as));
    memset(bs,0,sizeof(bs));
    for(int i=0;i<a.size();i++)if(a[a.size()-i-1]>='0'&&a[a.size()-i-1]<='9')as[i]=a[a.size()-i-1]-'0';
    for(int i=0;i<b.size();i++)if(b[b.size()-i-1]>='0'&&b[b.size()-i-1]<='9')bs[i]=b[b.size()-i-1]-'0';
    len=max(a.size(),b.size());
    for(int i=0;i<len;i++)
        cs[i]=as[i]+bs[i];
    for(int i=0;i<len;i++)
        if(cs[i]>9)
        {
            cs[i+1]++;
            cs[i]-=10;
            if(i==len-1)len++;
        }
    while(cs[len]==0)len--;
    for(int i=0;i<=len;i++)
    {
        char s=(cs[i]+'0');
        ans=s+ans;
    }
    // cout<<ans<<endl;
    return ans;
}
int main()
{
    // string a,b;
    // cin>>a>>b;
    // cout<<g(a,b)<<endl;

    cin>>n>>m>>x1>>y1;
    memset(no,true,sizeof(no));
    dp[0]="1";

    no[x1][y1]=false;
    for(int i=0;i<8;i++)no[x1+l[i]][y1+o[i]]=false;

    for(int i=1;i<=m;i++)
    {
        dp[i]=dp[i-1];
        if(no[0][i]==false)dp[i]="0";
    }

    k[0]="1";
    for(int i=1;i<=n;i++)
    {
        k[i]=k[i-1];
        if(no[i][0]==false)k[i]="0";
    }

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(j==1)
            {
                dp[j]=g(dp[j],k[i]);
            }
            else dp[j]=g(dp[j],dp[j-1]);
            if(no[i][j]==false)dp[j]="0";
            // cout<<dp[j]<<" ";
        }
        // for(int j=1;j<=m;j++)
        //     cout<<dp[j]<<" ";
        // cout<<endl;
    }
    cout<<dp[m]<<endl;
}

 

Guess you like

Origin www.cnblogs.com/jzxnl/p/11106399.html