当前位置:网站首页>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;
}边栏推荐
- Different perspectives
- AQS抽象队列同步器
- 洛谷入门1【顺序结构】题单题解
- 洛谷_P1003 [NOIP2011 提高组] 铺地毯_暴力枚举
- Today, Teng Xu came out with 37k during the interview. It's really a miracle. He showed me his skill
- Beginner level Luogu 1 [sequence structure] problem list solution
- Teach you how to realize pynq-z2 bar code recognition
- Pri3d: a representation learning method for 3D scene perception using inherent attributes of rgb-d data
- 关于 SAP UI5 参数 $$updateGroupId 前面两个 $ 符号的含义
- Talk about redis transactions
猜你喜欢

CV领域一代宗师黄煦涛教授86岁冥诞,UIUC专设博士奖学金激励新锐
![[digital signal processing] discrete time signal (analog signal, discrete time signal, digital signal | sampling leads to time discrete | quantization leads to amplitude discrete)](/img/80/28d53985d56d64ca721b26e846c667.jpg)
[digital signal processing] discrete time signal (analog signal, discrete time signal, digital signal | sampling leads to time discrete | quantization leads to amplitude discrete)

Derivation of Halcon camera calibration principle

Problems encountered in vs compilation

CAS comparison and exchange

直播app运营模式有哪几种,我们该选择什么样的模式?

HTTP Caching Protocol practice

Use GCC to generate an abstract syntax tree "ast" and dump it to Dot file and visualization

Admixture usage document Cookbook

VS编译遇到的问题
随机推荐
Is flutter easy to learn? How to learn? The most complete introduction and actual combat of flutter in history. Take it away without thanks~
About sitemap XML problems
Je veux acheter des produits à revenu fixe + mais je ne sais pas quels sont ses principaux investissements.
原子操作类
洛谷_P1007 独木桥_思维
February 16, 2022 freetsdb compilation and operation
What is the London Silver unit
sql注入原理
[issue 17] golang's one-year experience in developing Meitu
Design of UART controller based on FPGA (with code)
Indexeddb learning materials
ReentrantLock、ReentrantReadWriteLock、StampedLock
#28对象方法扩展
Go error collection | when a function uses a return value with a parameter name
Jupiter core error
可变参数模板 Variadic Templates
Design skills of main function of Blue Bridge Cup single chip microcomputer
Reflection learning summary
Beginner level Luogu 1 [sequence structure] problem list solution
Top ten Devops best practices worthy of attention in 2022