A: 牛牛的DRB迷宫I (dp)

8 篇文章 0 订阅

传送门

题意:

在这里插入图片描述

分析:

对于每个位置,看能不能从上,或者从左边到达,如果可以那就加上前面的方案数即可

代码:

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
#define Pll make_pair
using namespace std;
typedef long long ll;
const int maxn=2e5+50;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int phi=1e9+6;
const ll M=1e18+7;
int p[2050];
ll dp[150][150];
char ch[100][100];
int main()
{
    int n,m;
    scanf("%d%d ",&n,&m);
    for(int i=1;i<=n;i++) {
        for (int j = 1; j <= m; j++)
            scanf("%c", &ch[i][j]);
        getchar();
    }
        dp[1][1]=1;
        for(int i=2;i<=m;i++)
            if(ch[1][i-1]!='D')dp[1][i]=dp[1][i-1];
            for(int i=2;i<=n;i++)
                if(ch[i-1][1]!='R')dp[i][1]=dp[i-1][1];
                for(int i=2;i<=n;i++)
                    for(int j=2;j<=m;j++){
                        if(ch[i][j-1]!='D')dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;//能从左边到达
                        if(ch[i-1][j]!='R')dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;//能从上边到达
                    }
                
                printf("%lld\n",dp[n][m]);
    return 0;
}
/*
 
 */
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值