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;
}

codeforces 348D Turtles的更多相关文章

  1. Codeforces 348D Turtles LGV

    Turtles 利用LGV转换成求行列式值. #include<bits/stdc++.h> #define LL long long #define fi first #define s ...

  2. Codeforces.348D.Turtles(容斥 LGV定理 DP)

    题目链接 \(Description\) 给定\(n*m\)的网格,有些格子不能走.求有多少种从\((1,1)\)走到\((n,m)\)的两条不相交路径. \(n,m\leq 3000\). \(So ...

  3. CodeForces - 348D Turtles(LGV)

    https://vjudge.net/problem/CodeForces-348D 题意 给一个m*n有障碍的图,求从左上角到右下角两条不相交路径的方案数. 分析 用LGV算法.从(1,1)-(n, ...

  4. CodeForces 348D Turtles(LGV定理)题解

    题意:两只乌龟从1 1走到n m,只能走没有'#'的位置,问你两只乌龟走的时候不见面的路径走法有几种 思路:LGV定理模板.但是定理中只能从n个不同起点走向n个不同终点,那么需要转化.显然必有一只从1 ...

  5. CodeForces - 348D:Turtles(LGV定理)

    题意:给定N*M的矩阵,'*'表示可以通过,'#'表示不能通过,现在要找两条路径从[1,1]到[N,M]去,使得除了起点终点,没有交点. 思路:没有思路,就是裸题.  Lindström–Gessel ...

  6. Codeforces 348D DP + LGV定理

    题意及思路:https://www.cnblogs.com/chaoswr/p/9460378.html 代码: #include <bits/stdc++.h> #define LL l ...

  7. LGV定理 (CodeForces 348 D Turtles)/(牛客暑期多校第一场A Monotonic Matrix)

    又是一个看起来神奇无比的东东,证明是不可能证明的,这辈子不可能看懂的,知道怎么用就行了,具体看wikihttps://en.wikipedia.org/wiki/Lindstr%C3%B6m%E2%8 ...

  8. LGV 算法 (Lindström–Gessel–Viennot lemma)

    e(ai,bi)为从起点ai到终点bi的方案数.以上矩阵行列式结果就是(a1,a2,...an) 到 (b1,b2,...bn) 的所有不相交路径的种数. 具体证明的话看wiki,比较长.. 这个定理 ...

  9. Lindström–Gessel–Viennot lemma 应用两则

    对于一张无边权的DAG图,给定n个起点和对应的n个终点,这n条不相交路径的方案数为 det() (该矩阵的行列式) 其中e(a,b)为图上a到b的方案数 codeforces 348D [给定一张n* ...

随机推荐

  1. 百度前端技术学院-task1.8源代码

    主要是不采用bootstrap实现网格. 遇到的困难及注意点如下: 1.[class*='col-'],这个是选择col-开头的类,第一次用,以前也只是看到过: 2.媒体查询,总觉得容易理解错误.@m ...

  2. vs2013 update 2 cordova(phonegap) 环境

    1.win8.1(需激活) 2.vs2013 update 2 http://www.microsoft.com/zh-cn/download/details.aspx?id=42665  安装说明里 ...

  3. C#共享内存整理

    1.System.IO.MemoryMappedFiles 内存映射文件类 内存映射文件将文件的内容映射到应用程序的逻辑地址空间. 内存映射文件使程序员得以处理极大的文件(这是因为可以并发管理内存), ...

  4. CSS阴影盒子

    box-shadow:inset 横向偏移量  纵向偏移量  模糊范围  扩展范围  阴影颜色: 1.inset :(可选) 内阴影,不设置inset,表示盒子外部显示一个投影.也可写在最后. 2.横 ...

  5. 父页面向iframe子页面传递参数

    父页面: <iframe src="video.html" width="100%" height="400" name=" ...

  6. FileStream文件的使用

    // FileStream//(操作字节的)水一勺一勺的 可以操作任意格式的文件           //File一下子就读出来 //读取文本文件 // FileMode.OpenOrCreate你针 ...

  7. int类型转换byte类型

    计算机中,int类型占用4个字节,byte类型占用1个字节: 当int类型强转为byte类型时,计算机会截取最后的八位(1个字节): 由于计算机存储数据时,都是以补码的形式进行存储. 然而,我们通常看 ...

  8. fzu 2139 久违的月赛之二

    Problem 2139 久违的月赛之二 Accept: 42    Submit: 106Time Limit: 1000 mSec    Memory Limit : 32768 KB Probl ...

  9. scss-函数

    在scss中除了可以定义变量,具有@extend和@mixins等特性之外,还自备了一系列的函数功能. scss本身带有大量的内置函数,具体可以参阅官网函数模块. 一.字符串函数 unquote($s ...

  10. for、for..in、forEach、$.each等循环性能测试

    var num = 10000000,arr = []; for(i=0;i<num;i++){ arr[i] = i+2; } //1) 使用 for 循环 function test1() ...