当前位置:网站首页>洛谷_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;
}边栏推荐
- The global chip market may stagnate, and China's chip expansion accelerates to improve its self-sufficiency rate against the trend
- Brief reading of dynamic networks and conditional computing papers and code collection
- Redis CacheClient
- A brief analysis of the differences between domestic and foreign e-commerce
- 我想买固收+产品,但是不了解它主要投资哪些方面,有人知道吗?
- Lei Jun lost another great general, and liweixing, the founding employee of Xiaomi No. 12, left his post. He once had porridge to create Xiaomi; Intel's $5.4 billion acquisition of tower semiconductor
- LVI: feature extraction and sorting of lidar subsystem
- AQS抽象队列同步器
- AbortController的使用
- Knightctf 2022 web section
猜你喜欢

R language objects are stored in JSON

Massive data! Second level analysis! Flink+doris build a real-time data warehouse scheme

Reflection learning summary

反射学习总结
Principle Comparison and analysis of mechanical hard disk and SSD solid state disk

Synchronized and lock escalation

ThreadLocal之强、弱、软、虚引用

QT 如何在背景图中将部分区域设置为透明

Calcul de la confidentialité Fate - Prévisions hors ligne

Integration of entry-level SSM framework based on XML configuration file
随机推荐
ThreadLocal之强、弱、软、虚引用
Derivation of Halcon camera calibration principle
基于WEB平台的阅读APP设计与实现
Principle Comparison and analysis of mechanical hard disk and SSD solid state disk
What is the London Silver code
優雅的自定義 ThreadPoolExecutor 線程池
Computer screen splitting method
Leetcode 724. Find the central subscript of the array (yes, once)
我想买固收+产品,但是不了解它主要投资哪些方面,有人知道吗?
On traversal of tree nodes
522. longest special sequence II / Sword finger offer II 101 Split equal sum subset
R language objects are stored in JSON
Knowledge map model
What is the London Silver unit
Integration of entry-level SSM framework based on XML configuration file
Interpretation of new version features of PostgreSQL 15 (including live Q & A and PPT data summary)
Let's talk about the process of ES Indexing Documents
机械硬盘和ssd固态硬盘的原理对比分析
Privacy computing fat offline prediction
About the meaning of the first two $symbols of SAP ui5 parameter $$updategroupid