[Dynamic] knight tour planning

Original title Portal

Thinking


This question I have a little bit to open a small array, the result of repeated investigation and not make mistakes because, he just wasted one hour on so simple a question, the results of the on-line digital slightest increase, the AC on this ...... lesson tells us that man can not save too QAQ, next time I would rather open space and do not waste time QAQ ......

Code


#include <iostream>
using namespace std;
long long dp[55][55];
int i,j,n,m,x_1,x2,y_1,y2;
int main()
{
    cin>>n>>m>>x_1>>y_1>>x2>>y2;
    dp[x_1][y_1]=1;
    for(i=x_1+1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            dp[i][j]=dp[i-1][j-2]*(i-1>0&&j-2>0)+dp[i-1][j+2]*(i-1>0&&j+2<=m)+dp[i-2][j+1]*(i-2>0&&j+1<=m)+dp[i-2][j-1]*(i-2>0&&j-1>0);
        }
    }
    cout<<dp[x2][y2];
    return 0;

}

Guess you like

Origin www.cnblogs.com/gongdakai/p/11488152.html