当前位置:网站首页>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;
}边栏推荐
- Understand the application scenario and implementation mechanism of differential segment
- Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions
- Exercise 9-3 plane vector addition
- 洛谷P5194 [USACO05DEC]Scales S 题解
- 7-9 find a small ball with a balance
- Doris学习笔记之数据表的创建
- Exercise 8-2 calculate the sum and difference of two numbers
- String substitution
- NPM install is stuck with various strange errors of node NPY
- js . Find the first palindrome string in the array
猜你喜欢

puzzle(016.3)千丝万缕

编程语言:类型系统的本质

Exercise 10-3 recursive implementation of exponential functions

Exercise 6-1 classify and count the number of characters

使用并行可微模拟加速策略学习

Exercise 10-8 recursive implementation of sequential output of integers

Sword finger offer 28 Symmetric binary tree

Leetcode(4)——寻找两个正序数组的中位数

X86 assembly language - Notes from real mode to protected mode

7-8 overspeed judgment
随机推荐
Exercise 9-1 time conversion
Tiantu investment sprint Hong Kong stocks: asset management scale of 24.9 billion, invested in xiaohongshu and Naixue
Polestar美股上市:5.5万台交付如何支持得起超200亿美元估值
7-28 monkeys choose King (Joseph problem)
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
7-15 calculation of PI
LNMP环境mail函数不能发送邮件解决
Onmenusharetimeline custom shared content is invalid, and the title and icon are not displayed
洛谷P3065 [USACO12DEC]First! G 题解
npm install卡住与node-npy的各种奇怪报错
战略、战术(和 OKR)
Facebook 如何将 Instagram 从 AWS 搬到自己的服务器
Exercise 8-8 moving letters
X86 assembly language - Notes from real mode to protected mode
US stock listing of polar: how can the delivery of 55000 units support the valuation of more than 20billion US dollars
Statistical capital consonants
7-22 tortoise and rabbit race (result oriented)
Too many files with unapproved license
How Facebook moves instagram from AWS to its own server
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.)