排列组合( Lindström–Gessel–Viennot lemma 定理)
链接:https://www.nowcoder.com/acm/contest/139/A
来源:牛客网
Monotonic Matrix
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 524288K,其他语言1048576K
64bit IO Format: %lld
题目描述
Count the number of n x m matrices A satisfying the following condition modulo (109+7). * Ai, j ∈ {0, 1, 2} for all 1 ≤ i ≤ n, 1 ≤ j ≤ m. * Ai, j ≤ Ai + 1, j for all 1 ≤ i < n, 1 ≤ j ≤ m. * Ai, j ≤ Ai, j + 1 for all 1 ≤ i ≤ n, 1 ≤ j < m.
输入描述:
The input consists of several test cases and is terminated by end-of-file.Each test case contains two integers n and m.
输出描述:
For each test case, print an integer which denotes the result.
示例1
输入
复制
1 2
2 2
1000 1000
输出
复制
6
20
540949876
备注:
* 1 ≤ n, m ≤ 103* The number of test cases does not exceed 105.
题意:
求有多少n*m的矩阵满足:
1.每个数都是0或1或2
2.a(i,j)<=a(i+1,j)
3.a(i,j)<=a(i,j+1)
题解:
链接:https://blog.csdn.net/black_miracle/article/details/81128169
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 2005
const ll mod=1e9+;
ll C[MAX][MAX];
void c()
{
for(int i=;i<MAX;i++)
{
C[i][]=;
for(int j=;j<=i;j++)
C[i][j]=(C[i-][j-]+C[i-][j])%mod;
}
}
int main()
{
c();
int n,m;
while(cin>>n>>m)
{
cout<<((C[n+m][n]*C[n+m][n])%mod-(C[n+m][n-]*C[n+m][n+])%mod+mod)%mod<<endl; //加+mod是为了防止出现负数
}
}
该题是一个定理来着,具体看这个链接:https://blog.csdn.net/qq_25576697/article/details/81138213
排列组合( Lindström–Gessel–Viennot lemma 定理)的更多相关文章
- Lindström–Gessel–Viennot lemma定理 行列式板子
https://blog.csdn.net/qq_37025443/article/details/86537261 博客 下面是wiki上的讲解,建议耐心地看一遍...虽然看了可能还是不懂 http ...
- Nowcoder Monotonic Matrix ( Lindström–Gessel–Viennot lemma 定理 )
题目链接 题意 : 在一个 n * m 的矩阵中放置 {0, 1, 2} 这三个数字.要求 每个元素 A(i, j) <= A(i+1, j) && A(i, j) <= ...
- 牛客网多校训练第一场 A - Monotonic Matrix(Lindström–Gessel–Viennot lemma)
链接: https://www.nowcoder.com/acm/contest/139/A 题意: 求满足以下条件的n*m矩阵A的数量模(1e9+7):A(i,j) ∈ {0,1,2}, 1≤i≤n ...
- 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* ...
- 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 ...
- Lindström–Gessel–Viennot lemma
解决不相交路径计数 有两个大小为N的点集A,B A上每一个点对应着B的每一个点 求满足条件的路径集合有多少个 图里面可能还有一些障碍 Codeforces 348 D 有一个N*M的网格图 有两个点 ...
- 2017ACM暑期多校联合训练 - Team 8 1011 HDU 6143 Killer Names (容斥+排列组合,dp+整数快速幂)
题目链接 Problem Description Galen Marek, codenamed Starkiller, was a male Human apprentice of the Sith ...
- 学习sql中的排列组合,在园子里搜着看于是。。。
学习sql中的排列组合,在园子里搜着看,看到篇文章,于是自己(新手)用了最最原始的sql去写出来: --需求----B, C, F, M and S住在一座房子的不同楼层.--B 不住顶层.C 不住底 ...
随机推荐
- pyspider启动错误解决(Python 3.7)
问题一 安装好pyspider之后,在启动的时候,报出上图错误. 原因 async和await从 python3.7 开始已经加入保留关键字中. 参考: What’s New In Python 3. ...
- 2019-1-24-WPF-文字描边
title author date CreateTime categories WPF 文字描边 lindexi 2019-01-24 19:47:18 +0800 2019-1-24 19:40:7 ...
- 246-基于TI DSP TMS320C6678、Altera FPGA的CPCI处理卡
基于TI DSP TMS320C6678.Altera FPGA的CPCI处理卡 1.板卡概述 本板卡由我公司自主研发,基于CPCI架构,符合CPCI2.0标准,采用两片TI DSP TMS320C ...
- springboot创建一个服务,向eureka中注册,使用swagger2进行服务管理
首先pom.xml文件,spring boot.springcloud版本很麻烦,容易出问题 <?xml version="1.0" encoding="UTF-8 ...
- [BZOJ5305] [HAOI2018] 苹果树 数学 组合计数
Summary 题意很清楚: 小 \(C\) 在自己家的花园里种了一棵苹果树, 树上每个结点都有恰好两个分支. 经过细心的观察, 小 \(C\) 发现每一天这棵树都会生长出一个新的结点. 第一天的时候 ...
- php 从7.0升级到7.2
下面的方法安装的php是非线程安全的,apache2服务器用不了 1. 添加Ondřej Surý提供的PHP源: sudo apt-get install software-properties-c ...
- 【leetcode】1012. Complement of Base 10 Integer
题目如下: Every non-negative integer N has a binary representation. For example, 5 can be represented a ...
- auto_now_add与auto_now的区别
- mybatis模糊查询(转载)
原文地址:http://blog.csdn.net/luqin1988/article/details/7865643 模糊查询: 1. sql中字符串拼接 SELECT * FROM tableNa ...
- dubbo-go 的开发、设计与功能介绍
dubbo-go 的前世今生 dubbo-go 是目前 Dubbo 多语言生态最火热的项目.dubbo-go 最早的版本应该要追溯到 2016 年,由社区于雨同学编写 dubbo-go 的初版.当时很 ...