当前位置:网站首页>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;
}边栏推荐
- 556. The next larger element III
- Toast UI editor (editor allows you to edit your markup document using text or WYSIWYG, with syntax highlighting, scrolling synchronization, real-time preview and chart functions.)
- Statistical capital consonants
- allegro,orcad, net alias,port,off-page connector之间的异同点和如何选取
- 数学常数表 by q779
- 2021年区域赛ICPC沈阳站J-Luggage Lock(代码简洁)
- JS shift operators (< <,> > and > > >)
- concat和concat_ws()区别及group_concat()和repeat()函数的使用
- Strategy, tactics (and OKR)
- 7-19 check denomination (solve binary linear equation)
猜你喜欢

556. The next larger element III

Tiantu investment sprint Hong Kong stocks: asset management scale of 24.9 billion, invested in xiaohongshu and Naixue

Print. JS -- web page file printing

7-10 calculate salary

7-11 calculation of residential water charges by sections

Similarities and differences between Allegro, OrCAD, net alias, port, off page connector and how to select them

JS matrix zero

ShowMeBug入驻腾讯会议,开启专业级技术面试时代

NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon

7-7 12-24 hour system
随机推荐
基因家族特征分析 - 染色体定位分析
fpga阻塞赋值和非阻塞赋值
Polestar美股上市:5.5万台交付如何支持得起超200亿美元估值
必贝特医药冲刺科创板:年营收97万亏损1.37亿 拟募资20亿
动态获取权限
修改数据库中的记录为什么报这个错
MongoDB索引
Common commands for getting started with mongodb database
7-10 calculate salary
SSH access control, blocking the IP when logging in repeatedly to prevent brute force cracking
Thread.sleep和TimeUnit.SECONDS.sleep的区别
一文了解微分段应用场景与实现机制
Leetcode (4) -- find the median of two positively ordered arrays
Strategy, tactics (and OKR)
Exercise 6-6 use a function to output an integer in reverse order
JS shift operators (< <,> > and > > >)
适用于XP的DDK
Exercise 7-6 count capital consonants
洛谷P5536 【XR-3】核心城市 题解
Exercise 10-3 recursive implementation of exponential functions