当前位置:网站首页>Luogu_ P1002 [noip2002 popularization group] crossing the river_ dp
Luogu_ P1002 [noip2002 popularization group] crossing the river_ dp
2022-06-27 15:33:00 【This question AC sleep again】
Luogu _P1002 [NOIP2002 Popularization group ] River crossing pawn _dp

// Positive solution
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=22;
bool mp[N][N];
LL dp[N][N];
int dx[]={ 0,1,1,-1,-1,2,2,-2,-2 };
int dy[]={ 0,2,-2,2,-2,1,-1,1,-1 };
int n,m,a,b;
void init()
{
memset( mp,true,sizeof( mp ) );
int i,j,tx,ty;
for( i=0;i<9;i++ )
{
tx=a+dx[i]; ty=b+dy[i];
if( tx>=0 && tx<=n && ty>=0 && ty<=m ) mp[tx][ty]=false;
}
memset( dp,0,sizeof( dp ) );
for( i=0;i<=n;i++ )
if( mp[i][0] ) dp[i][0]=1;
else break; //
for( j=0;j<=m;j++ )
if( mp[0][j] ) dp[0][j]=1;
else break; //
}
int main()
{
int i,j;
while( cin>>n>>m>>a>>b )
{
init();
for( i=1;i<=n;i++ )
for( j=1;j<=m;j++ )
if( mp[i][j] ) //
dp[i][j]=dp[i-1][j]+dp[i][j-1];
cout<<dp[n][m]<<endl;
}
return 0;
}//
Estimated size
// Accessibility Max
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=21;
LL dp[N][N];
int main()
{
int i,j;
memset( dp,0,sizeof( dp ) );
dp[1][1]=1;
for( i=1;i<N;i++ )
for( j=1;j<N;j++ )
if( i!=1 || j!=1 )
dp[i][j]=dp[i-1][j]+dp[i][j-1];
cout<<dp[20][20]<<endl;
return 0;
}
// 35345263800
// C( 40,20 )
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL C( LL n,LL m )
{
if( n<m ) return 0;
if( n==m || m==0 ) return 1;
LL ans,i; n=n-m+1;
for( ans=i=1;i<=m;i++ )
{
ans*=n++; ans/=i;
}
return ans;
}
int main()
{
cout<<C( 40,20 )<<endl;
return 0;
}
// 137846528820// dfs_TLE
#include<bits/stdc++.h>
using namespace std;
const int N=33;
bool used[N][N];
int dx[]={ 0,1 };
int dy[]={ 1,0 };
int dxx[]={ 0,1,1,-1,-1,2,2,-2,-2 };
int dyy[]={ 0,2,-2,2,-2,1,-1,1,-1 };
int n,m,a,b;
long long ans;
bool is_error( int x,int y )
{ // Specially ,x==n && y==m
if( x<0 || x>n || y<0 || y>m ) return true; // The border
for( int i=0;i<9;i++ )
if( x==a+dxx[i] && y==b+dyy[i] ) // The horse's control point
return true;
return false;
}
void dfs( int x,int y )
{
if( is_error( x,y ) ) return ; // prune
if( x==n && y==m ) { ans++; return ; } // Required
int i,tx,ty;
for( i=0;i<2;i++ ) // Loop traversal + Mark
{
tx=x+dx[i]; ty=y+dy[i];
if( used[tx][ty]==0 )
{
used[tx][ty]=1;
dfs( tx,ty );
used[tx][ty]=0;
}
}
}
int main()
{
while( cin>>n>>m>>a>>b )
{
memset( used,0,sizeof( used ) );
ans=0; dfs( 0,0 );
cout<<ans<<endl;
}
return 0;
}边栏推荐
- SQL parsing practice of Pisa proxy
- Synchronized and lock escalation
- SQL parsing practice of Pisa proxy
- volatile与JMM
- 522. 最长特殊序列 II / 剑指 Offer II 101. 分割等和子集
- Use of abortcontroller
- Handling methods for NVIDIA deepstream running delay, jamming and crash
- Numerical extension of 27es6
- Design of spread spectrum communication system based on FPGA (with main code)
- [advanced mathematics] from normal vector to surface integral of the second kind
猜你喜欢

Let's talk about the process of ES Indexing Documents
Talk about redis transactions

CAS comparison and exchange

2022年最新《谷粒学院开发教程》:8 - 前台登录功能

原子操作类

Synchronized and lock escalation

ReentrantLock、ReentrantReadWriteLock、StampedLock

Using redis skillfully to realize the like function, isn't it more fragrant than MySQL?

What is the London Silver code

直播app运营模式有哪几种,我们该选择什么样的模式?
随机推荐
How QT sets some areas to be transparent in the background image
我想买固收+产品,但是不了解它主要投资哪些方面,有人知道吗?
Cesium 使用MediaStreamRecorder 或者MediaRecorder录屏并下载视频,以及开启摄像头录像。【转】
Redis CacheClient
Different perspectives
避孕套巨头过去两年销量下降40% ,下降原因是什么?
Handling methods for NVIDIA deepstream running delay, jamming and crash
Web chat room system based on SSM
Create a database and use
洛谷_P1008 [NOIP1998 普及组] 三连击_枚举
关于 Spartacus 的 sitemap.xml 问题
Redis CacheClient
CentOS8-postgresql初始化时报错:initdb: error: invalid locale settings; check LANG and LC_* environment
Synchronized与锁升级
Piblup test report 1- pedigree based animal model
ERROR L104: MULTIPLE PUBLIC DEFINITIONS
手机号码的格式
基于SSM的Web网页聊天室系统
[digital signal processing] discrete time signal (discrete time signal knowledge points | signal definition | signal classification | classification according to certainty | classification according t
漏洞复现----34、yapi 远程命令执行漏洞