2 solutions

  • 2
    @ 2024-8-5 11:04:16
    #include<bits/stdc++.h>
    using namespace std;
    const int N=25;
    typedef long long LL;
    LL f[N][N];
    int dx[]={-2,-2,-1,-1,0,1,1,2,2};
    int dy[]={-1,1,-2,2,0,-2,2,-1,1};
    LL st[N][N];
    LL ans; 
    LL n,m,cx,cy;
    void dfs(LL x,LL y)
    {
     
        if(x>n||y>m) return ; //越界 
        if(st[x][y]==1) return ; //控制点 
        if(x==n&&y==m) //答案 
        {
            ans++;
            return ;    
        }   
        dfs(x,y+1);
        dfs(x+1,y);
    }
    int main()
    {
     
        cin>>n>>m>>cx>>cy;
        n++,m++,cx++,cy++;
        for(int i=0;i<9;i++) //标记控制点 
        {
            int a=cx+dx[i];
            int b=cy+dy[i];
            st[a][b]=1;
        }
        dfs(1,1);
        cout<<ans;
        return 0;
    }
    
    • 1
      @ 2026-2-23 19:27:13
      #include<bits/stdc++.h>
      using namespace std;
      typedef long long LL;
      const int N=45;
      LL f[N][N];
      int dx[]={-2,-2,-1,-1,1,1,2,2,0};
      int dy[]={-1,1,-2,2,-2,2,-1,1,0};
      bool st[N][N]; 
      int main()
      {
      	int n,m,cx,cy;
      	cin>>n>>m>>cx>>cy;
      	n++,m++,cx++,cy++;
      	f[0][1]=1;
      	for(int d=0;d<9;d++)
      	{
      		int a=cx+dx[d],b=cy+dy[d];
      		st[a][b]=1;
      	}
      	for(int i=1;i<=n;i++)
      	{
      		for(int j=1;j<=m;j++)
      		{
      			if(st[i][j]) continue;
      			f[i][j]=f[i-1][j]+f[i][j-1];
      		}
      	}
      	cout<<f[n][m];
      	return 0;
      }
      
      
      • 1

      Information

      ID
      236
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      3
      Tags
      (None)
      # Submissions
      50
      Accepted
      14
      Uploaded By