zoukankan      html  css  js  c++  java
  • The King's Walk(DP)

    Chess is a game in which two sides control pieces in an attempt to capture each other’s king. The pieces vary in mobility. At the beginning of a game the kings are rather vulnerable. They are less mobile than most other pieces and they tend to hide behind their pawns. Like in real life, as soon as both queens have left the game it is time for the kings to come into action. Because there is little threat left for the king, he can now move safely around the board. Indeed his mobility seems to be quite strong at this stage making him one of the more dangerous pieces. Your task is to measure the mobility of the king in the endgame.

    Consider a chess board of N×NN×N squares. The king is the only piece on the board. He starts at a given position and wants to go to another given position in the minimum number of moves. The king can move to any adjacent square in any orthogonal or diagonal direction.

    Input

    The input starts with a line containing an integer TT (1T1001≤T≤100), the number of test cases. Then for each test case:

    • One line with a single integer NN, the size of the board, where 2N50002≤N≤5000.

    • One line with four space-separated integers X1,Y1,X2,Y2X1,Y1,X2,Y2, such that 1X1,Y1,X2,Y2N1≤X1,Y1,X2,Y2≤N, where (X1,Y1X1,Y1) is the square on which the king starts and (X2,Y2X2,Y2) is the square the king wants to go to (different from his starting position).

    Output

    For each test case, output one line with a single integer: the number of ways by which the king can reach the destination square in the minimum number of moves. As this number can be very large, you must reduce your answer modulo 53180085318008.

    Sample Input 1Sample Output 1
    2
    3
    1 2 3 2
    8
    2 2 7 7
    
    3
    1

    题意:

    在一个n*n棋盘上,从(x1,y1)到(x2,y2),能直着走,斜着走,在最少步数的前提下,有几种方案?

    思路:

    x坐标y坐标分别作差,大的那个即为最少步数,

    假设大的是x,可以把这看做x层,每层在左右方向上可以不走,可以左走一步,可以右走一步,就酱

     1 #include <bits/stdc++.h>
     2 
     3 #define mod 5318008
     4 
     5 using namespace std;
     6 
     7 int a[5005][5005];
     8 
     9 int main()
    10 {
    11     int t, n, x1, x2, y1, y2, i, j, x, y;
    12     scanf("%d", &t);
    13     while(t--)
    14     {
    15         scanf("%d", &n);
    16         scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    17         x = abs(x1-x2);
    18         y = abs(y1-y2);
    19         if(x < y)
    20         {
    21             swap(x1, y1);
    22             swap(x2, y2);
    23             swap(x, y);
    24         }
    25         memset(a, 0, sizeof(a));
    26       //  printf("x=%d y1=%d y2=%d
    ", x, y1, y2);
    27         a[0][y1] = 1;
    28         for(i=1;i<=x;i++)
    29         {
    30             for(j=1;j<=n;j++)
    31             {
    32                 a[i][j] += a[i-1][j];
    33                 if(j-1>=1) a[i][j] += a[i-1][j-1];
    34                 if(j+1<=n) a[i][j] += a[i-1][j+1];
    35                 a[i][j] %= mod;
    36             }
    37         }
    38         printf("%d
    ", a[x][y2]);
    39     }
    40     return 0;
    41 }
  • 相关阅读:
    Brain network involved in autonomic functions 与自主功能相关的大脑网络
    Brief summary of classical components of ERP 事件相关成分(ERP)经典成分小结
    ICA & Percentage Variance Account For (PVAF)
    数据处理中白化Whitening的作用图解分析
    Loadings vs eigenvectors in PCA 主成分分析(PCA)中的负荷和特征向量
    主成分分析(PCA)和独立成分分析(ICA)相关资料
    Sketch of heart and QRS complex 心脏及QRS波群简图
    Brain Network visulation in EEG 脑电网络可视化
    Phase Locking Value (PLV) 神经信号的锁相值
    ubuntu16.04下的一些基本操作笔记
  • 原文地址:https://www.cnblogs.com/0xiaoyu/p/12846858.html
Copyright © 2011-2022 走看看