Codeforces 348D Turtles LGV

Turtles

利用LGV转换成求行列式值。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long

using namespace std;

const int N = 3000 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double PI = acos(-1);

int n, m, dp1[N][N], dp2[N][N];
char s[N][N];
void solve(int sx, int sy, int dp[N][N]) {
    if(s[sx][sy] != '#') dp[sx][sy] = 1;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if(s[i][j] == '#') continue;
            dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
            dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
        }
    }
}
int main() {
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
    solve(1, 2, dp1);
    solve(2, 1, dp2);
    printf("%d\n", (1ll * dp1[n - 1][m] * dp2[n][m - 1] % mod  - 1ll * dp1[n][m - 1] * dp2[n - 1][m] % mod + mod) % mod);
    return 0;
}

/*
*/

 

上一篇:LOJ 116 有源汇有上下界最大流


下一篇:Linux项目部署、项目启动、查看进程、查看日志