当前位置:网站首页>洛谷_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;
}边栏推荐
- 我想買固收+產品,但是不了解它主要投資哪些方面,有人知道嗎?
- How to change a matrix into a triple in R language (i.e. three columns: row, col, value)
- Nvidia Deepstream 运行延迟,卡顿,死机处理办法
- Integration of entry-level SSM framework based on XML configuration file
- 522. longest special sequence II / Sword finger offer II 101 Split equal sum subset
- Pisa-Proxy 之 SQL 解析实践
- Talk about redis transactions
- AutoCAD - line width setting
- Today, Teng Xu came out with 37k during the interview. It's really a miracle. He showed me his skill
- Abnormal analysis of pcf8591 voltage measurement data
猜你喜欢

Interview question: rendering 100000 data solutions

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

Pri3d: a representation learning method for 3D scene perception using inherent attributes of rgb-d data

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

Leetcode 724. 寻找数组的中心下标(可以,一次过)

QT notes (XXVIII) using qwebengineview to display web pages

Design and implementation of reading app based on Web Platform

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

基于WEB平台的阅读APP设计与实现

AQS抽象队列同步器
随机推荐
关于 Spartacus 的 sitemap.xml 问题
QT notes (XXVIII) using qwebengineview to display web pages
What is the London Silver code
Interpretation of new version features of PostgreSQL 15 (including live Q & A and PPT data summary)
At a time of oversupply of chips, China, the largest importer, continued to reduce imports, and the United States panicked
2022-06-27日报:Swin Transformer、ViT作者等共话:好的基础模型是CV研究者的朴素追求
A brief analysis of the differences between domestic and foreign e-commerce
522. 最长特殊序列 II / 剑指 Offer II 101. 分割等和子集
Redis master-slave replication, sentinel mode, cluster cluster
Cannot determine value type from string ‘<p>1</p>‘
Today, Teng Xu came out with 37k during the interview. It's really a miracle. He showed me his skill
[PHP code injection] common injectable functions of PHP language and utilization examples of PHP code injection vulnerabilities
Library management system
Design skills of main function of Blue Bridge Cup single chip microcomputer
Excuse me, is it cost-effective to insure sunshine Optimus Prime term life insurance No. 7? What are the advantages of this product?
[microservices sentinel] hotspot rules | authorization rules | cluster flow control | machine list
巧用redis实现点赞功能,它不比mysql香吗?
[xman2018 qualifying] pass
AQS抽象队列同步器
How to change a matrix into a triple in R language (i.e. three columns: row, col, value)