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;
}
codeforces 348D Turtles的更多相关文章
- Codeforces 348D Turtles LGV
Turtles 利用LGV转换成求行列式值. #include<bits/stdc++.h> #define LL long long #define fi first #define s ...
- Codeforces.348D.Turtles(容斥 LGV定理 DP)
题目链接 \(Description\) 给定\(n*m\)的网格,有些格子不能走.求有多少种从\((1,1)\)走到\((n,m)\)的两条不相交路径. \(n,m\leq 3000\). \(So ...
- CodeForces - 348D Turtles(LGV)
https://vjudge.net/problem/CodeForces-348D 题意 给一个m*n有障碍的图,求从左上角到右下角两条不相交路径的方案数. 分析 用LGV算法.从(1,1)-(n, ...
- CodeForces 348D Turtles(LGV定理)题解
题意:两只乌龟从1 1走到n m,只能走没有'#'的位置,问你两只乌龟走的时候不见面的路径走法有几种 思路:LGV定理模板.但是定理中只能从n个不同起点走向n个不同终点,那么需要转化.显然必有一只从1 ...
- CodeForces - 348D:Turtles(LGV定理)
题意:给定N*M的矩阵,'*'表示可以通过,'#'表示不能通过,现在要找两条路径从[1,1]到[N,M]去,使得除了起点终点,没有交点. 思路:没有思路,就是裸题. Lindström–Gessel ...
- Codeforces 348D DP + LGV定理
题意及思路:https://www.cnblogs.com/chaoswr/p/9460378.html 代码: #include <bits/stdc++.h> #define LL l ...
- LGV定理 (CodeForces 348 D Turtles)/(牛客暑期多校第一场A Monotonic Matrix)
又是一个看起来神奇无比的东东,证明是不可能证明的,这辈子不可能看懂的,知道怎么用就行了,具体看wikihttps://en.wikipedia.org/wiki/Lindstr%C3%B6m%E2%8 ...
- LGV 算法 (Lindström–Gessel–Viennot lemma)
e(ai,bi)为从起点ai到终点bi的方案数.以上矩阵行列式结果就是(a1,a2,...an) 到 (b1,b2,...bn) 的所有不相交路径的种数. 具体证明的话看wiki,比较长.. 这个定理 ...
- Lindström–Gessel–Viennot lemma 应用两则
对于一张无边权的DAG图,给定n个起点和对应的n个终点,这n条不相交路径的方案数为 det() (该矩阵的行列式) 其中e(a,b)为图上a到b的方案数 codeforces 348D [给定一张n* ...
随机推荐
- 使用eclipse 开发lisp
https://www.ibm.com/developerworks/cn/opensource/os-eclipse-lispcusp/ eclipse有一个插件,可以支持lisp的开发,叫cusp ...
- when coding in a fresh system
I have designed a component of a web system with my workmate. In detail, I am just a coder instead o ...
- 各种IDE的使用
sharpdevelop http://blog.sina.com.cn/s/blog_d1001bff0101di7p.html
- Dllmain的作用
DllMain函数是DLL模块的默认入口点.当Windows加载DLL模块时调用这一函数.系统首先调用全局对象的构造函数,然后调用全局函数 DLLMain.DLLMain函数不仅在将DLL链接加载到进 ...
- JSP学习笔记(4)-Javabean
按照sun公司的定义,Javabean是一个可重复使用的软件组件,实际上Javabean是一种Java类,通过封装属性和方法成为具有某种功能或处理某个业务的对象,简称Bean,Javabean基于ja ...
- Django基础必备三神装(HttpResponse、render,、redirect)
在使用三神装的时候,首先当然是得要导入它们: from django.shortcuts import HttpResponse, render, redirect 1.HttpResponse 它是 ...
- 使用vue+webpack打包时,去掉资源前缀
在build文件夹下找到webpack.prod.conf.js文件,搜索 filename: utils.assetsPath('css/[name].[contenthash].css'), 将[ ...
- hexo的next主题个性化教程:打造炫酷网站
看到有些next主题的网站很炫酷,那么是怎么配置的呢?接下来我会讲一讲如何实现一些炫酷的效果 主要有以下32种: 在右上角或者左上角实现fork me on github 添加RSS 添加动态背景 实 ...
- Nib加载的方式实现自定义TableView
实现的效果 实现原理: 通过在主界面中用Bundle 的LoadNib的方式进行自定义窗体文件加载并渲染界面 实现步骤 Step One 创建TableViewCell 窗体 Step Two 定义接 ...
- BZOJ1597: [Usaco2008 Mar]土地购买(dp 斜率优化)
题意 题目链接 Sol 重新看了一遍斜率优化,感觉又有了一些新的认识. 首先把土地按照\((w, h)\)排序,用单调栈处理出每个位置第向左第一个比他大的位置,显然这中间的元素是没用的 设\(f[i] ...