Codeforces 348 D - Turtles
D - Turtles
思路:
LGV 定理 (Lindström–Gessel–Viennot lemma)
从{\(a_1\),\(a_2\),...,\(a_n\)} 到 {\(b_1\),\(b_2\),...,\(b_n\)}的不相交路径数等于行列式
c(a_1, b_1) & c(a_1, b_2) & ... & c(a_1, b_n) \\
c(a_2, b_1) & c(a_2, b_2) & ... & c(a_2, b_n) \\
... & ... & ... & ... \\
c(a_n, b_1) & c(a_n, b_2) & ... &c(a_n, b_n) \\
\end{array}
\right ]}
\]
的值。其中,\(c(a_i, b_i)\) 表示从点 \(a_i\) 到点 \(b_i\) 的路径方案数。
那么这道题就是求一个二阶行列式的值
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head
const int N = 3e3 + 5;
const int MOD = 1e9 + 7;
int dp[N][N], n, m;
char s[N][N];
int solve(int a, int b, int c, int d) {
for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) dp[i][j] = 0;
for (int i = a; i <= c; ++i) {
for (int j = b; j <= d; ++j) {
if(i == a && j == b) {
if(s[i][j] == '.') dp[i][j] = 1;
}
else {
if(s[i][j] == '.') dp[i][j] = (dp[i-1][j]+dp[i][j-1])%MOD;
}
}
}
return dp[c][d];
}
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; ++i) scanf("%s", s[i]+1);
printf("%lld\n", (solve(1, 2, n-1, m)*1LL*solve(2, 1, n, m-1) - solve(1, 2, n, m-1)*1LL*solve(2, 1, n-1, m)%MOD+MOD)%MOD);
return 0;
}
Codeforces 348 D - Turtles的更多相关文章
- LGV定理 (CodeForces 348 D Turtles)/(牛客暑期多校第一场A Monotonic Matrix)
又是一个看起来神奇无比的东东,证明是不可能证明的,这辈子不可能看懂的,知道怎么用就行了,具体看wikihttps://en.wikipedia.org/wiki/Lindstr%C3%B6m%E2%8 ...
- Codeforces 348 D - Turtles Lindström–Gessel–Viennot lemma
#include<bits/stdc++.h> using namespace std; #define y1 y11 #define fi first #define se second ...
- CF 348 D. Turtles
D. Turtles 链接 题意: 给定一个N*M的棋盘,有些格子不能走,问有多少种从(1,1)到(N,M)的两条不相交路径. 分析: lGV定理. 定理:点集A={a1,a2,…an}A={a1,a ...
- CodeForces - 348D:Turtles(LGV定理)
题意:给定N*M的矩阵,'*'表示可以通过,'#'表示不能通过,现在要找两条路径从[1,1]到[N,M]去,使得除了起点终点,没有交点. 思路:没有思路,就是裸题. Lindström–Gessel ...
- 做题记录 To 2019.2.13
2019-01-18 4543: [POI2014]Hotel加强版:长链剖分+树形dp. 3653: 谈笑风生:dfs序+主席树. POJ 3678 Katu Puzzle:2-sat问题,给n个变 ...
- Lindström–Gessel–Viennot lemma
解决不相交路径计数 有两个大小为N的点集A,B A上每一个点对应着B的每一个点 求满足条件的路径集合有多少个 图里面可能还有一些障碍 Codeforces 348 D 有一个N*M的网格图 有两个点 ...
- codeforces 348D Turtles
codeforces 348D Turtles 题意 题解 代码 #include<bits/stdc++.h> using namespace std; #define fi first ...
- Codeforces Round #202 (Div. 1) D. Turtles DP
D. Turtles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/547/problem/B ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance
题目链接: http://codeforces.com/contest/669/problem/D 题意: 给你一个初始序列:1,2,3,...,n. 现在有两种操作: 1.循环左移,循环右移. 2. ...
随机推荐
- KMeans聚类
常用的聚类方法: ①分裂方法: K-Means算法(K-平均).K-MEDOIDS算法(K-中心点).CLARANS算法(基于选择的算法) ②层次分析方法: BIRCH算法(平衡迭代规约和聚类).CU ...
- Object.defineProperty()方法学习笔记
这是js中一个非常重要的方法,ES6中某些方法的实现依赖于它,VUE通过它实现双向绑定 此方法会直接在一个对象上定义一个新属性,或者修改一个已经存在的属性, 并返回这个对象 参数 Object.def ...
- Red Hat Enterprise 6.5 在虚拟机上将系统语言修改为中文
Red Hat Enterprise 6.5 在虚拟机上将系统语言修改为中文 说明:本文是个人在使用RedHat时候为方便而设置的,作为学习札记记录. 在虚拟机安装RedHat时候会跳过语言的安装选项 ...
- ASP.NET MVC4中的异步控制器
在抛弃了对.NET 3的支持之后, ASP.NET MVC 4 彻底拥抱了Task类库, 你不需要再蛋疼的给每个Action写两个方法, 也无需傻傻的手动对异步Action计数器增减了(AsyncMa ...
- Soda Machine【差分+离散化】
题目链接:https://ac.nowcoder.com/acm/contest/1106/A 题目大意: 1.一条长1e9的线段,每个节点都可以上色.给出n次操作,每次操作将[l, r]区间内的节点 ...
- 3、1 ElasticSearch
文档 类型 索引 行 表 数据库 是引擎 一.新建文档 1.以post发送提交 2.http://127.0.0.1:9200/索引/类型 3.body:{ "title&quo ...
- 【Polya计数】Buildings II
Buildings II 题目描述 As a traveling salesman in a globalized world, Alan has always moved a lot. He alm ...
- SAS学习笔记35 options语句
- canvas绘制文本自动换行
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...
- win10 右键新建卡顿
前段时间不知道自己搞啥了,右键变得很慢,找了一些常规的解决方案,什么清除注册表等等的,对我来说,没好用. 然后将就继续使用,然后觉得是office的问题,卸载,重装2010的,发现还是一样卡... 继 ...