当前位置:网站首页>洛谷_P1002 [NOIP2002 普及组] 过河卒_dp
洛谷_P1002 [NOIP2002 普及组] 过河卒_dp
2022-06-27 15:23:00 【这题AC再睡.】
洛谷_P1002 [NOIP2002 普及组] 过河卒_dp

// 正解
#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;
}//
预估规模
// 无障碍最大值
#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 )
{ // 特别地,x==n && y==m
if( x<0 || x>n || y<0 || y>m ) return true; // 边界
for( int i=0;i<9;i++ )
if( x==a+dxx[i] && y==b+dyy[i] ) // 马的控制点
return true;
return false;
}
void dfs( int x,int y )
{
if( is_error( x,y ) ) return ; // 剪枝
if( x==n && y==m ) { ans++; return ; } // 所求
int i,tx,ty;
for( i=0;i<2;i++ ) // 循环遍历+标记
{
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;
}边栏推荐
- [issue 17] golang's one-year experience in developing Meitu
- Atomic operation class
- Redis master-slave replication, sentinel mode, cluster cluster
- Naacl 2022 | TAMT: search the transportable Bert subnet through downstream task independent mask training
- Teach you how to package and release the mofish Library
- Volatile and JMM
- 優雅的自定義 ThreadPoolExecutor 線程池
- [digital signal processing] discrete time signal (analog signal, discrete time signal, digital signal | sampling leads to time discrete | quantization leads to amplitude discrete)
- Great God developed the new H5 version of arXiv, saying goodbye to formula typography errors in one step, and the mobile phone can easily read literature
- 隱私計算FATE-離線預測
猜你喜欢

Acwing game 57

Tsinghua & Shangtang & Shanghai AI & CUHK proposed Siamese image modeling, which has both linear probing and intensive prediction performance

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

2022-2-16 learning the imitated Niuke project - Section 6 adding comments

All you want to know about large screen visualization is here
![[advanced MySQL] MTS master-slave synchronization principle and Practice Guide (7)](/img/d6/1b916f49ad02dee4ab2c26add324df.png)
[advanced MySQL] MTS master-slave synchronization principle and Practice Guide (7)

AI begets the moon, and thousands of miles share the literary heart

Computer screen splitting method

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

隱私計算FATE-離線預測
随机推荐
Sword finger offer II 039 Histogram maximum rectangular area monotonic stack
Great God developed the new H5 version of arXiv, saying goodbye to formula typography errors in one step, and the mobile phone can easily read literature
LVI: feature extraction and sorting of lidar subsystem
Pri3d: a representation learning method for 3D scene perception using inherent attributes of rgb-d data
ReentrantLock、ReentrantReadWriteLock、StampedLock
原子操作类
What are the operating modes of the live app? What mode should we choose?
At a time of oversupply of chips, China, the largest importer, continued to reduce imports, and the United States panicked
PostgreSQL 15新版本特性解读(含直播问答、PPT资料汇总)
Talk about redis transactions
522. 最长特殊序列 II / 剑指 Offer II 101. 分割等和子集
How to change a matrix into a triple in R language (i.e. three columns: row, col, value)
[issue 17] golang's one-year experience in developing Meitu
Use GCC to generate an abstract syntax tree "ast" and dump it to Dot file and visualization
Synchronized与锁升级
老师能给我说一下固收+产品主要投资于哪些方面?
Volatile and JMM
做一篇人人能搞懂的ThreadLocal(源码)
QT 如何在背景图中将部分区域设置为透明
Overseas warehouse knowledge popularization