正常跑可以AC,但开了洛谷的O2后会RE#1,WA#3。想问一问原因。 代码如下:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define HACK freopen("test.in", "r", stdin);freopen("test.out", "w", stdout);
// #define LOCAL_JUDGE
ll dp[25][25];
bool vis[25][25];
int x,y,x_0,y_0;
int dx[8]={2,1,-1,-2,-2,-1,1,2};
int dy[8]={1,2,2,1,-1,-2,-2,-1};
bool check(int a,int b)
{
return a>=0&&a<=x&&b>=0&&b<=y;
}
int main()
{
#ifdef LOCAL_JUDGE
HACK;
#endif
cin>>x>>y>>x_0>>y_0;
vis[x_0][y_0]=1;
for(int i=0;i<8;++i)
{
vis[x_0+dx[i]][y_0+dy[i]]=1;
}
//init
dp[0][0]=1;
for(int i=0;i<=x;++i)
for(int j=0;j<=y;++j)
{
if(i==0&&j==0) continue;
if(vis[i][j]==1) continue;
ll ans=0;
if(check(i,j-1)&&!vis[i][j-1]) ans+=dp[i][j-1];
if(check(i-1,j)&&!vis[i-1][j]) ans+=dp[i-1][j];
dp[i][j]=ans;
}
// dp
cout<<dp[x][y];
return 0;
}