20分求助

P1002 [NOIP2002 普及组] 过河卒

# 改成40分 ```cpp #include<iostream> using namespace std; long long dp[21][21]; int e[21][21]; int main(){ int n,m,x,y; cin>>n>>m>>x>>y; for(int i=0;i<=n;i++){ for(int j=0;j<=m;j++){ e[i][j]=1; } } e[x][y]=0; e[x-2][y-1]=0; e[x-1][y-2]=0; e[x+1][y+2]=0; e[x+2][y+1]=0; e[x+2][y-1]=0; e[x+1][y-2]=0; e[x-1][y+2]=0; e[x-2][y+1]=0; if(e[0][0]==0||(e[1][0]==0&&e[0][1]==0)){ cout<<0; return 0; } dp[0][0]=1; for(int i=1;i<=n;i++){ if(e[i][0]==0){ dp[i][0]=0; }else{ dp[i][0]=dp[i-1][0]; } } for(int i=1;i<=m;i++){ if(e[0][i]==0){ dp[0][i]=0; }else{ dp[0][i]=dp[0][i-1]; } } // for(int i=0;i<=n;i++){ // for(int j=0;j<=n;j++){ // cout<<dp[i][j]<<' '; // } // cout<<endl; // } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(e[i][j]==0){ continue; } dp[i][j]=dp[i-1][j]+dp[i][j-1]; } } cout<<dp[n][m]; return 0; } ```
by Albet @ 2019-12-07 09:58:13


```c #include<cstdio> const int Const[2][9]={{0,-2,-1,1,2,2,1,-1,-2},{0,1,2,2,1,-1,-2,-2,-1}}; long long DP[21][21]={1}; bool mark[21][21]; int main() { int nx,ny,hx,hy; scanf("%d%d%d%d",&nx,&ny,&hx,&hy); for(int i=0;i<9;++i) if(hx+Const[0][i]>=0&&hx+Const[0][i]<=nx&&hy+Const[1][i]>=0&&hy+Const[1][i]<=ny) mark[hx+Const[0][i]][hy+Const[1][i]]=1; for(int i=0;i<=nx;++i) for(int j=0;j<=ny;++j) { if(i) DP[i][j]+=DP[i-1][j]; if(j) DP[i][j]+=DP[i][j-1]; DP[i][j]*=!mark[i][j]; } printf("%lld",DP[nx][ny]); return 0; } ```
by wwhang @ 2019-12-07 10:01:34


@[wwhang](/user/161653) 能解释一下吗
by Albet @ 2019-12-07 10:20:26


@[wwhang](/user/161653) 谢谢
by Albet @ 2019-12-07 10:28:37


80分版,仅供参考和找茬 ``` #include <iostream> using namespace std; int main(){ long long a[24][24]; int i,j,p,q,m,n; for(i=0;i<24;i++){ for(j=0;j<25;j++){ a[i][j]=0; } } cin>>p>>q; cin>>i>>j; i=i+2;j=j+2;p=p+2;q=q+2; a[i+1][j+2]=-1;a[i-1][j-2]=-1; a[i-1][j+2]=-1;a[i+1][j-2]=-1; a[i+2][j+1]=-1;a[i-2][j-1]=-1; a[i-2][j+1]=-1;a[i+2][j-1]=-1; a[i][j]=-1;a[2][2]=1; for(i=0;i<2;i++){ for(j=0;j<24;j++){ a[i][j]=0; } } for(i=0;i<24;i++){ for(j=0;j<2;j++){ a[i][j]=0; } } for(m=2;m<22;m++){ for(n=2;n<22;n++){ if(m==2&&n==2){continue;} if(a[m][n]==-1){a[m][n]=0;} else{a[m][n]=a[m-1][n]+a[m][n-1];} } } /*for(i=0;i<24;i++){ for(j=0;j<23;j++){ cout<<a[i][j]<<' '; }cout<<a[i][24]<<endl; }*/ cout<<a[p][q]<<endl; return 0; } ``` (wa 是第三个点,求那个点的数据)
by yyf1000001000 @ 2020-02-10 15:19:34


@[Albet](/user/275090)
by yyf1000001000 @ 2020-02-10 15:19:55


|