• 洛谷P1002过河卒-题解


    原题:

     思路:

    显然是计数DP

    又是在网格上,又是只能走下和右,思路是很显然的

    想要到达这个点,只能由这个点上方和左方的点转移来

    方程也很明显了:

    f[i][j]=f[i-1][j]+f[i][j+1];

    注意特判被马占的点就可以了

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    int n, m, x, y;
    unsigned long long f[25][25];
    int book[25][25];
    int fx[] = {0, -2, -1, 1, 2, 2, 1, -1, -2};
    int fy[] = {0, 1, 2, 2, 1, -1, -2, -2, -1};
    int main()
    {
        scanf("%d %d %d %d", &n, &m, &x, &y);
        n++;
        m++;
        x++;
        y++;
        book[x][y] = 1;
        f[1][1] = 1;
        for (int i = 1; i <= 8; i++)
            book[x + fx[i]][y + fy[i]] = 1;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                if (book[i][j] == 0)
                    f[i][j] = max(f[i - 1][j] + f[i][j - 1], f[i][j]);
        printf("%llu
    ", f[n][m]);
        return 0;
    }
    

      

  • 相关阅读:
    C#基础
    C#基础
    Sqlserver数据库备份和还原
    C#基础
    Python3学习笔记4
    Python3学习笔记3
    调用接口Post xml和json数据的通用方法
    Python3学习笔记2
    Python3学习笔记1
    常见的PHP函数代码性能对比
  • 原文地址:https://www.cnblogs.com/lujin49/p/13835854.html
Copyright © 2020-2023  润新知