当前位置:网站首页>[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 .
边栏推荐
- Find an SQL that can judge the data in the table and only fill in the SQL that is not overwritten
- 灵活的IP网络测试工具——— X-Launch
- 抖音實戰~關注博主
- The company leader said that if the personal code exceeds 10 bugs, he will be dismissed. What is the experience?
- How can we speed up the chunksplitter when CDC extracts MySQL data in full?
- How to clean the nozzle of Epson l3153 printer
- filinCdc 的sql,多表的时候总报这个错,请问下该怎么解决呀
- To quickly download JDK, in addition to the official Oracle download, is there a download address for the latest version available in China
- C语言全局变量(c文件和h文件中的全局变量、静态全局变量)使用注意事项
- Has anyone ever used CDC to synchronize to MySQL with a deadlock?
猜你喜欢

恭喜我自己,公众号粉丝破万

Sword finger offer 47 Maximum gift value (DP)

代码理解:IMPROVING CONVOLUTIONAL MODELS FOR HANDWRITTEN TEXT RECOGNITION

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

Introduction to SQLSERVER database

CUPTI error: CUPTI could not be loaded or symbol could not be found.

2022年中国音频市场年度综合分析

CUPTI error: CUPTI could not be loaded or symbol could not be found.

Learning about DC-DC step-down chip of sy8120i (12V reduced to 3.3V)

Huawei's 9-year experience as a software testing director
随机推荐
有人用cdc同步到mysql发生过死锁吗?
Multithreading and high concurrency IV: varhandle, strong weak virtual reference and ThreadLocal
How to traverse collections Ordereddict, taking it and forgetting items
C语言全局变量(c文件和h文件中的全局变量、静态全局变量)使用注意事项
With the transformation of automatic empowerment, Feihe dairy accelerates its move towards digitalization!
Learning about DC-DC step-down chip of sy8120i (12V reduced to 3.3V)
求一个能判断表中数据,只填充不覆盖的sql
Taco: a data enhancement technique for character recognition
Find an SQL that can judge the data in the table and only fill in the SQL that is not overwritten
JS逆向之巨量星图sign签名
leetcode:714. The best time to buy and sell stocks includes handling fee [DP dual status]
Design a stack with getmin function
Matlab exercises -- exercises related to symbolic operation
控制器的功能和工作原理
Has anyone ever used CDC to synchronize to MySQL with a deadlock?
10:00面试,10:02就出来了 ,问的实在是太...
Resolve cross domain
抖音实战~取关博主
Flinkcdc collects Oracle, and the Oracle database is CDB's
视频直播系统源码,倒计时显示,商品秒杀倒计时




