当前位置:网站首页>[noip2002 popularization group] cross the river pawn
[noip2002 popularization group] cross the river pawn
2022-06-28 04:46:00 【Pandaoxi】
Go through all the hardships , I finally A C AC AC La !
[NOIP2002 Popularization group ] River crossing pawn
Title Description
On the chessboard A A A There is a river crossing pawn , Need to get to the goal B B B spot . The rules of pawn walking : You can go down 、 Or to the right . At the same time on the chessboard C C C
There's a horse on the other side , The point where the horse is located and all the points that can be reached in one step of jumping are called the control points of the opposing horse . So it's called “ A pawn crossing the river ”.The chessboard is represented by coordinates , A A A spot ( 0 , 0 ) (0, 0) (0,0)、 B B B spot ( n , m ) (n, m) (n,m), The same coordinates of the horse's position need to be given .
Now I ask you to calculate the number of soldiers from A A A Point can reach B B B The number of paths of points , Suppose the horse's position is fixed , It's not a step by step .
Input format
Four positive integers in a row , respectively B B B Point coordinates and horse coordinates .
Output format
An integer , Indicates the number of paths .
Examples #1
The sample input #1
6 6 3 3Sample output #1
6Tips
about 100 % 100 \% 100% The data of , 1 ≤ n , m ≤ 20 1 \le n, m \le 20 1≤n,m≤20, 0 ≤ 0 \le 0≤ Horse coordinates ≤ 20 \le 20 ≤20.
【 Title source 】
NOIP 2002 Question 4 of the popularization group
Let's look at this problem together , yes NOIP The last question of ( For my kind of konjaku , It's already very difficult ), The algorithmic label given by Luogu official is dynamic programming !
Let's think about it , Simplify if you can .
Before that , Let's think about one thing first , For example, this grid , We from S S S Go to the E E E, How many different ways to walk ?
It's simple , Elementary school mathematics filling method .
alike , Let's think about , Simulate their position , Find the recurrence relation :
Obvious , a ( i , j ) = a ( i − 1 , j ) + a ( i , j − 1 ) a(i,j)=a(i-1,j)+a(i,j-1) a(i,j)=a(i−1,j)+a(i,j−1) Is the relation of this question , It is also the relation of this big problem .
Now? , Let's think about this problem .
alike , We can be sure , Show the coordinates where the horse can move , Then mark 0.
( Pay attention to this question l o n g l o n g long\ long long long Ha , Otherwise it's out of range )
// input data
long long a[100][100]={
};
int n,m,x,y;
cin>>n>>m>>x>>y;
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
a[i][j]=1;
}
}
// Represents the coordinates of the horse
a[x][y]=0;
if(x-2>=0&&y-1>=0) a[x-2][y-1]=0;
if(x-2>=0&&y+1<=m) a[x-2][y+1]=0;
if(x-1>=0&&y-2>=0) a[x-1][y-2]=0;
if(x-1>=0&&y+2<=m) a[x-1][y+2]=0;
if(x+1<=n&&y-2>=0) a[x+1][y-2]=0;
if(x+2<=n&&y-1>=0) a[x+2][y-1]=0;
if(x+2<=n&&y+1<=m) a[x+2][y+1]=0;
if(x+1<=n&&y+2<=m) a[x+1][y+2]=0;

Judge whether you crossed the line , If you cross the line , You can't move .
Recursion of the core , Here it is :
i = 0 i=0 i=0 It's the first line , Except for control points , Only from the left , a ( i , j ) = a(i,j)= a(i,j)= The value on the left side
j = 0 j=0 j=0 It's the first column , Except for control points , Only from above , a ( i , j ) = a(i,j)= a(i,j)= The value above
The rest , Except for control points , Sum according to the previous relation a ( i , j ) = a ( i − 1 , j ) + a ( i , j − 1 ) a(i,j)=a(i-1,j)+a(i,j-1) a(i,j)=a(i−1,j)+a(i,j−1)
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
if(i==0&&j==0) continue;
if(a[i][j]==0) continue;
if(i==0) a[i][j]=a[i][j-1];
else if(j==0) a[i][j]=a[i-1][j];
else a[i][j]=a[i-1][j]+a[i][j-1];
}
}
Finally, simply , The output is over .
cout<<a[n][m];
/* // Output the number of each position for(int i=0;i<=n;i++){ for(int j=0;j<=m;j++){ cout<<a[i][j]<<" "; } cout<<endl; } */
A complete map :
1 1 1 1 1 1 1
1 2 0 1 0 1 2
1 0 0 1 1 0 2
1 1 1 0 1 1 3
1 0 1 1 2 0 3
1 1 0 1 0 0 3
1 2 2 3 3 3 6
The complete code is as follows :
// Author:PanDaoxi
#include <iostream>
using namespace std;
int main(){
long long a[100][100]={
};
int n,m,x,y;
cin>>n>>m>>x>>y;
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
a[i][j]=1;
}
}
a[x][y]=0;
if(x-2>=0&&y-1>=0) a[x-2][y-1]=0;
if(x-2>=0&&y+1<=m) a[x-2][y+1]=0;
if(x-1>=0&&y-2>=0) a[x-1][y-2]=0;
if(x-1>=0&&y+2<=m) a[x-1][y+2]=0;
if(x+1<=n&&y-2>=0) a[x+1][y-2]=0;
if(x+2<=n&&y-1>=0) a[x+2][y-1]=0;
if(x+2<=n&&y+1<=m) a[x+2][y+1]=0;
if(x+1<=n&&y+2<=m) a[x+1][y+2]=0;
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
if(i==0&&j==0) continue;
if(a[i][j]==0) continue;
if(i==0) a[i][j]=a[i][j-1];
else if(j==0) a[i][j]=a[i-1][j];
else a[i][j]=a[i-1][j]+a[i][j-1];
}
}
cout<<a[n][m];
/* for(int i=0;i<=n;i++){ for(int j=0;j<=m;j++){ cout<<a[i][j]<<" "; } cout<<endl; } */
return 0;
}
Luogu A C AC AC .
边栏推荐
- Multithreading and high concurrency IV: varhandle, strong weak virtual reference and ThreadLocal
- Lamaba expression learning and common functional interfaces
- Database garbled
- 【Linux】【Mysql】ERROR 1698 (28000): Access denied for user ‘root‘@‘localhost‘
- How can we speed up the chunksplitter when CDC extracts MySQL data in full?
- 10: 00 interview, came out at 10:02, the question is really too
- mysql修改密码报错需要怎么做
- 27年,微软IE结束了!
- 视频直播系统源码,倒计时显示,商品秒杀倒计时
- Introduction to multi project development, basic design class library project use
猜你喜欢

Web3来临时的风口浪尖

一文详解|增长那些事儿

On the necessity of building a video surveillance convergence platform and its scenario application

Necessary skills for test and development: actual combat of security test vulnerability shooting range

TACo:一种关于文字识别的数据增强技术

Multi thread implementation rewrites run (), how to inject and use mapper file to operate database

Role of native keyword

Analyse complète annuelle du marché chinois de l'audio en 2022

UI automation test framework construction - write an app automation

Secouer le son et se battre ~ prêter attention au blogueur
随机推荐
With the transformation of automatic empowerment, Feihe dairy accelerates its move towards digitalization!
first. Net core MVC project
What are the password requirements for waiting insurance 2.0? What are the legal bases?
Matlab exercises -- exercises related to symbolic operation
Tiktok practice ~ pay attention to bloggers
OracleData安装问题
RT thread bidirectional linked list (learning notes)
JS逆向之巨量星图sign签名
Secouer le son et se battre ~ prêter attention au blogueur
抖音实战~取关博主
快速下载JDK,除了官方Oracle下载,还有国内可以有最新版本的下载地址吗
Little knowledge about function templates --
The company leader said that if the personal code exceeds 10 bugs, he will be dismissed. What is the experience?
Multi thread implementation rewrites run (), how to inject and use mapper file to operate database
Source code of live video system, countdown display, countdown of commodity spike
Go language learning tutorial (14)
AspNetCoreRateLimit 速率限制 接口访问限制 限流控制
Flinkcdc collects Oracle, and the Oracle database is CDB's
Huawei's 9-year experience as a software testing director
如何遍历collections.OrderedDict,服了又忘记items




