[第十一届蓝桥杯省赛C++B组]走方块 原创
算法标签:DP
题目简叙

思路
1.i== 2|| j==2不可走
 2.边缘初始化一步
 3.当前位子的可能等于左边和上边的数量之和:dp[i][j]=dp[i-1][j]+dp[i][j-1];
代码
#include<iostream>
#include<cstring>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    
    const int nlen=n,mlen=m;
    int res=0;
    
    int dp[nlen+10][mlen+10];
    memset(dp,0,sizeof dp);
    
    for(int i=1;i<=nlen;i++)
        for(int j=1;j<=mlen;j++){
            if(i % 2 == 0 && j % 2 == 0) continue;
            else if(i==1||j==1)dp[i][j]=1;    
            else dp[i][j]=dp[i-1][j]+dp[i][j-1];
        }
        
    cout<<dp[nlen][mlen];
    
    return 0;
}
AC截图

 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号