2 solutions

  • 0
    @ 2024-8-5 11:16:07
    #include<bits/stdc++.h>
    using namespace std;
    const int N=25;
    long long 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};
    long long st[N][N];
    long long ans; 
    long long n,m,cx,cy;
    void dfs(long long x,long long 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;
    }
    
    • 0
      @ 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

      Information

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