当前位置:网站首页>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;
}边栏推荐
- js 2023. String pair equal to the target string after connection
- Eight sorts
- Print. JS -- web page file printing
- 7-8 overspeed judgment
- TS code automatically generates JS
- 6-9 statistics of single digits (15 points)
- ZABBIX saves the page blank after adding calculated items
- 八大排序
- 556. 下一个更大元素 III
- Stop asking yourself if you are suitable for software testing
猜你喜欢

Eight sorts

中感微冲刺科创板:年营收2.4亿净亏1782万 拟募资6亿

Solution to failure or slow downloading of electron when electron uses electron builder to package

Exercise 10-1 calculate the sum of 1 to n using recursive functions

7-15 calculation of PI

Sword finger offer 28 Symmetric binary tree

Leetcode (4) - - trouver la médiane de deux tableaux ordonnés positifs

MySQL multi table query subquery

x86汇编语言-从实模式到保护模式 笔记

Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions
随机推荐
7-17 crawling worms (break exercise)
x86汇编语言-从实模式到保护模式 笔记
SSH access control, blocking the IP when logging in repeatedly to prevent brute force cracking
7-9 find a small ball with a balance
泰凌冲刺科创板:拟募资13亿 国家大基金与小米长江是股东
编程语言:类型系统的本质
Jiuyi cloud black free encryption free version source code
Duet date picker (time plug-in that can manually enter the date)
allegro,orcad, net alias,port,off-page connector之间的异同点和如何选取
556. 下一个更大元素 III
八大排序
Too many files with unapproved license
虽然不一定最优秀,但一定是最努力的!
ConstraintLayout 的使用
Programming language: the essence of type system
分布式事务(Seata) 四大模式详解
添加Zabbix计算类型项目Calculated items
Statistical capital consonants
Exercise 6-1 classify and count the number of characters
Fabric. JS document