题意及思路:https://www.cnblogs.com/chaoswr/p/9460378.html

代码:

#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 3010;
const LL mod = 1000000007;
LL dp[maxn][maxn];
char s[maxn][maxn];
int n, m;
LL ans[4];
void solve(int sx, int sy, LL ans[]) {
if(s[sx][sy] == '#') return;
memset(dp, 0, sizeof(dp));
dp[sx][sy] = 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
if(s[i][j] == '#') continue;
if(s[i + 1][j] != '#' && i < n) dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod;
if(s[i][j + 1] != '#' && j < m) dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % mod;
}
ans[0] = dp[n - 1][m], ans[1] = dp[n][m - 1];
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%s", s[i] + 1);
solve(1, 2, ans);
solve(2, 1, &ans[2]);
printf("%lld\n", (ans[0] * ans[3] % mod - ans[1] * ans[2] % mod + mod) % mod);
}

  

Codeforces 348D DP + LGV定理的更多相关文章

  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定理)题解

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

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

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

  4. codeforces 348D Turtles

    codeforces 348D Turtles 题意 题解 代码 #include<bits/stdc++.h> using namespace std; #define fi first ...

  5. LGV定理

    LGV定理用于解决路径不相交问题. 定理 有 \(n\) 个起点 \(1, 2, 3, ..., n\),它们 分别对应 要到 \(n\) 个终点 \(A, B, C, ..., X\),并且要求路径 ...

  6. 【bzoj2111】[ZJOI2010]Perm 排列计数 dp+Lucas定理

    题目描述 称一个1,2,...,N的排列P1,P2...,Pn是Mogic的,当且仅当2<=i<=N时,Pi>Pi/2. 计算1,2,...N的排列中有多少是Mogic的,答案可能很 ...

  7. HDU 5852 Intersection is not allowed! ( 2016多校9、不相交路径的方案、LGV定理、行列式计算 )

    题目链接 题意 : 给定方格中第一行的各个起点.再给定最后一行与起点相对应的终点.问你从这些起点出发到各自的终点.不相交的路径有多少条.移动方向只能向下或向右 分析 : 首先对于多起点和多终点的不相交 ...

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

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

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

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

随机推荐

  1. jsonp详细原理之一

    /*script标签是不存在跨域请求的,类似的还有img,background:url,link 你可以想象一下,平时的这些标签都是可以直接引入外部资源的,所以是不存在跨域问题的*/ function ...

  2. 2019牛客多校第一场E ABBA 贪心 + DP

    题意:问有多少个有(n + m)个A和(n + m)个B的字符串可以凑出n个AB和m个BA. 思路:首先贪心的发现,如果从前往后扫,遇到了一个A,优先把它看成AB的A,B同理.这个贪心策略用邻项交换很 ...

  3. Codeforces 1100E 拓扑排序

    题意及思路:https://blog.csdn.net/mitsuha_/article/details/86482347 如果一条边(u, v),v的拓扑序小于u, 那么(u, v)会形成环,要反向 ...

  4. python convert csv to xlsx

    搬运:http://stackoverflow.com/questions/17684610/python-convert-csv-to-xlsx import os import glob impo ...

  5. 备份Oracle 数据库。

    #!/bin/bash# 2018-07-07 oracle database back#filename=`date +%Y%m%d`filename=`date +%Y_%m_%d_%H%M`di ...

  6. java 延时

    Java中主要有两种方法来实现延迟,即:Thread和Timer 1.普通延时用Thread.sleep(int)方法,这很简单.它将当前线程挂起指定的毫秒数.如try{Thread.currentT ...

  7. PostgreSQL按年月日分组(关键词:extract time as Year/Month/Day)

    Select EXTRACT(year from cast(joindate as timestamp)) as Year, EXTRACT(month from cast(joindate as t ...

  8. QByteArray和十六进制的QString(char*)相互转换

    #include <QCoreApplication> #include <QDebug> #include <QDataStream> QByteArray He ...

  9. [NOIP模拟测试37]反思+题解

    一定要分析清楚复杂度再打!!!窝再也不要花2h20min用暴力对拍暴力啦!!! 雨露均沾(滑稽),尽量避免孤注一掷.先把暴力分拿全再回来刚正解. 即使剩下的时间不多了也优先考虑认真读题+打暴力而非乱搞 ...

  10. 在 MacBook 上安装 Ubuntu

    建立ubuntu 安裝U盤,加入usb port,按住option key 開機,正常安裝. 完成後,會缺少wifi drive sudo apt-get install bcmwl-kernel-s ...