当前位置:网站首页>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;
}
边栏推荐
- Mongodb index
- 7-20 print 99 formula table (format output)
- Add ZABBIX calculation type itemcalculated items
- Recent learning summary
- Leetcode(4)——寻找两个正序数组的中位数
- npm install卡住与node-npy的各种奇怪报错
- 6-9 statistics of single digits (15 points)
- TS code automatically generates JS
- 7-4 BCD decryption (10 points)
- 好看、好用、强大的手写笔记软件综合评测:Notability、GoodNotes、MarginNote、随手写、Notes Writers、CollaNote、CollaNote、Prodrafts、Noteshelf、FlowUs、OneNote、苹果备忘录
猜你喜欢
天谋科技 Timecho 完成近亿元人民币天使轮融资,打造工业物联网原生时序数据库
中感微冲刺科创板:年营收2.4亿净亏1782万 拟募资6亿
八大排序
Exercise 8-7 string sorting
Sword finger offer 28 Symmetric binary tree
Exercise 9-1 time conversion
Why is this error reported when modifying records in the database
7-7 12-24 hour system
Understanding of closures
分布式事务(Seata) 四大模式详解
随机推荐
How to bold text in AI
Sendmail无法发送邮件及发送过慢解决
Sub-GHz无线解决方案Z-Wave 800 系列ZG23 soc和ZGM230S模块
牛客网:过河卒
J-luggage lock of ICPC Shenyang station in 2021 regional games (simple code)
concat和concat_ws()区别及group_concat()和repeat()函数的使用
7-9 find a small ball with a balance
Eight sorts
Too many files with unapproved license
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
Ultra simple mobile map development
分布式事务(Seata) 四大模式详解
fpga阻塞赋值和非阻塞赋值
JS get DPI, PX to cm, cm to PX
超简单手机地图开发
Print. JS -- web page file printing
Exercise 10-1 judge the three digits that meet the conditions
别再问自己适不适合做软件测试了
Exercise 10-3 recursive implementation of exponential functions
Find the sum of the elements of each row of the matrix