codeforces 348D Turtles

codeforces 348D Turtles

题意

题解

代码

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
//---

const int N = 3030, P = 1e9+7;

int n, m;
int dp[2][N][N];
string s[N];

inline int add(int x, int y) {
    int res = x + y;
    if(res >= P) res -= P;
    return res;
}
inline int mul(int x, int y) {
    return 1ll * x * y % P;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cin >> n >> m;
    rep(i, 1, n+1) {
        cin >> s[i];
        s[i] = " " + s[i];
    }
    dp[0][1][2] = (s[1][2] == '.');
    dp[1][2][1] = (s[2][1] == '.');
    rep(i, 1, n+1) rep(j, 1, m+1) if(s[i][j] == '.') {
        rep(t, 0, 2) dp[t][i][j] = add(dp[t][i][j], add(dp[t][i-1][j], dp[t][i][j-1]));
    }
    int ans = mul(dp[0][n-1][m], dp[1][n][m-1]);
    int res = mul(dp[0][n][m-1], dp[1][n-1][m]);
    ans = add(ans, P - res);
    cout << ans << endl;
    return 0;
}

转载于:https://www.cnblogs.com/wuyuanyuan/p/9305322.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值