当前位置:网站首页>Niuke: crossing the river
Niuke: crossing the river
2022-07-03 14:24:00 【lsgoose】
Well , This question is obvious dp subject .
First write the dynamic transfer equation , set up dp[i][j] Representation coordinates (0,0) To (i,j) The number of paths , This number of paths is equal to the sum of the number of paths of the left node and the number of paths of the upper node , obviously dp[i][j]=dp[i-1][j]+dp[i][j-1], This is the case that this point can go . Of course , If this point can be reached by a horse , So directly dp[i][j]=0.
As for the concrete realization :
1. When judging the horse point , Directly judge the coordinates in the traversal process , The previous idea was to mark on the map first , Such an approach is still a little troublesome
2. Special assignments are required in the first column and row , The coordinate origin needs to be assigned 1
3. As for the data size, let's calculate 40 Internal selection 20 About the maximum order of magnitude , Probably 137846528820, then int The maximum value of 2147483647, Obviously , Here we need to use larger data types to store answers , such as long long
The code is as follows :
#include<bits/stdc++.h>
using namespace std;
int n,m,x,y;
// Check whether the coordinates are the points that the horse can reach
bool check(int i, int j, int x, int y){
return (abs(x-i) + abs(y-j) == 3 && x!=i && y!=j) || (x==i && y==j);
}
long long dp(vector<vector<long long>> &mp){
mp[0][0]=1;
for(int i=1;i<=n;++i){
mp[i][0] = (check(i, 0, x, y)) ? 0 : mp[i-1][0];
}
for(int j=1;j<=m;++j){
mp[0][j] = (check(0, j, x, y)) ? 0 : mp[0][j-1];
}
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
mp[i][j] = (check(i, j, x, y)) ? 0 : mp[i-1][j] + mp[i][j-1];
}
}
return mp[n][m];
}
int main(){
cin>>n>>m>>x>>y;
vector<vector<long long>> mp(n+1, vector<long long>(m+1, 0));
cout<<dp(mp)<<endl;
return 0;
}
边栏推荐
- Leetcode (4) -- find the median of two positively ordered arrays
- MySQL multi table query subquery
- x86汇编语言-从实模式到保护模式 笔记
- Zabbix添加Calculated items后保存页面成空白
- JS Part III
- JVM垃圾回收机
- 7-28 monkeys choose King (Joseph problem)
- 战略、战术(和 OKR)
- Stop asking yourself if you are suitable for software testing
- Preliminary summary of structure
猜你喜欢
556. 下一个更大元素 III
Fabric. JS document
Exercise 9-3 plane vector addition
Exercise 6-2 using functions to sum special A-string sequences
Mysql多表查询 #子查询
Doris学习笔记之数据表的创建
7-11 calculation of residential water charges by sections
[clean up the extraordinary image of Disk C]
Similarities and differences between Allegro, OrCAD, net alias, port, off page connector and how to select them
牛客网:过河卒
随机推荐
NPM install is stuck with various strange errors of node NPY
必贝特医药冲刺科创板:年营收97万亏损1.37亿 拟募资20亿
Exercise 8-7 string sorting
Exercise 8-8 moving letters
Similarities and differences between Allegro, OrCAD, net alias, port, off page connector and how to select them
Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions
Exercise 10-3 recursive implementation of exponential functions
JVM垃圾回收机
Accelerating strategy learning using parallel differentiable simulation
fpga阻塞赋值和非阻塞赋值
[clean up the extraordinary image of Disk C]
Exercise 6-1 classify and count the number of characters
Page generation QR code
八大排序
String reverse order
洛谷P3065 [USACO12DEC]First! G 题解
GRPC的四种数据流以及案例
分布式事务(Seata) 四大模式详解
泰凌冲刺科创板:拟募资13亿 国家大基金与小米长江是股东
US stock listing of polar: how can the delivery of 55000 units support the valuation of more than 20billion US dollars