博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
牛客假日团队赛11 H 过河卒(路径条数dp)
阅读量:4556 次
发布时间:2019-06-08

本文共 1665 字,大约阅读时间需要 5 分钟。

H过河卒

题目链接:

题目描述

如图,A 点有一个过河卒,需要走到目标 B 点。卒行走规则:可以向下、或者向右。同时在棋盘上的任一点有一个对方的马(如上图的C点),该马所在的点和所有跳跃一步可达的点称为对方马的控制点。例如上图 C 点上的马可以控制 9 个点(图中的P
1,P
2 … P
8 和 C)。卒不能通过对方马的控制点。
棋盘用坐标表示,A 点(0,0)、B 点(n,m)(n,m 为不超过 20 的整数,并由键盘输入),同样马的位置坐标是需要给出的(约定: C<>A,同时C<>B)。现在要求你计算出卒从 A 点能够到达 B 点的路径的条数。

输入描述:

输入B点的坐标(n,m)以及对方马的坐标(X,Y){不用判错}

输出描述:

输出一个整数(路径的条数)。
示例1

输入

6 6 3 2

输出

17 思路:dp,将不能走的点为1,其余点为0
//// Created by HJYL on 2019/8/21.//#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;const int maxn=1e6+10;int main() { int n,m,x,y; scanf("%d%d%d%d",&x,&y,&n,&m); ll dp[30][30]; ll a[30][30]; memset(dp,0,sizeof(dp)); memset(a,0,sizeof(a)); if(n>=0&&m>=0) a[n][m]=1; if (n - 2 >= 0 && m - 1 >= 0) a[n - 2][m - 1] = 1; if (n - 2 >= 0 && m + 1 >= 0) a[n - 2][m + 1] = 1; if (n - 1 >= 0 && m - 2 >= 0) a[n - 1][m - 2] = 1; if (n - 1 >= 0 && m + 2 >= 0) a[n - 1][m + 2] = 1; if (n + 1 >= 0 && m - 2 >= 0) a[n + 1][m - 2] = 1; if (n + 1 >= 0 && m + 2 >= 0) a[n + 1][m + 2] = 1; if (n + 2 >= 0 && m - 1 >= 0) a[n + 2][m - 1] = 1; if (n + 2 >= 0 && m + 1 >= 0) a[n + 2][m + 1] = 1; for(ll i=0;i<=x;i++) { dp[i][0]=1; if(a[i][0]==1) break; } for(ll i=0;i<=y;i++) { dp[0][i]=1; if(a[0][i]==1) break; } for(ll i=1;i<=x;i++) { for(ll j=1;j<=y;j++) { if(a[i][j-1]==0) dp[i][j]+=dp[i][j-1]; if(a[i-1][j]==0) dp[i][j]+=dp[i-1][j]; } } printf("%lld\n",dp[x][y]); return 0;}

 

 

转载于:https://www.cnblogs.com/Vampire6/p/11390007.html

你可能感兴趣的文章
20180923-WebService
查看>>
z变换
查看>>
Python - 静态函数(staticmethod), 类函数(classmethod), 成员函数
查看>>
Spring基础2
查看>>
【灵异短篇】这个夜晚有点凉
查看>>
一点小问题
查看>>
pytest 10 skip跳过测试用例
查看>>
MVC身份验证及权限管理
查看>>
It was not possible to find any compatible framework version
查看>>
关于8.0.15版本的mysql下载与安装
查看>>
Redis主从复制看这篇就够了
查看>>
洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth 题解
查看>>
(4.20)SQL Server数据库启动过程,以及启动不起来的各种问题的分析及解决技巧...
查看>>
基本数据类型(数字和字符串)
查看>>
函数__装饰器
查看>>
linux system函数分析
查看>>
前端优化措施
查看>>
论学习汉语和学习编程的异同点
查看>>
linux img文件压缩及解压
查看>>
Linux 下的 scp
查看>>