链接: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 定理)的更多相关文章

  1. Lindström–Gessel–Viennot lemma定理 行列式板子

    https://blog.csdn.net/qq_37025443/article/details/86537261 博客 下面是wiki上的讲解,建议耐心地看一遍...虽然看了可能还是不懂 http ...

  2. Nowcoder Monotonic Matrix ( Lindström–Gessel–Viennot lemma 定理 )

    题目链接 题意 : 在一个 n * m 的矩阵中放置 {0, 1, 2} 这三个数字.要求 每个元素 A(i, j) <= A(i+1, j) && A(i, j) <= ...

  3. 牛客网多校训练第一场 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 ...

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

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

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

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

  6. 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 ...

  7. Lindström–Gessel–Viennot lemma

    解决不相交路径计数 有两个大小为N的点集A,B A上每一个点对应着B的每一个点 求满足条件的路径集合有多少个 图里面可能还有一些障碍 Codeforces 348 D 有一个N*M的网格图 有两个点 ...

  8. 2017ACM暑期多校联合训练 - Team 8 1011 HDU 6143 Killer Names (容斥+排列组合,dp+整数快速幂)

    题目链接 Problem Description Galen Marek, codenamed Starkiller, was a male Human apprentice of the Sith ...

  9. 学习sql中的排列组合,在园子里搜着看于是。。。

    学习sql中的排列组合,在园子里搜着看,看到篇文章,于是自己(新手)用了最最原始的sql去写出来: --需求----B, C, F, M and S住在一座房子的不同楼层.--B 不住顶层.C 不住底 ...

随机推荐

  1. jquery+ajax获取本地json对应数据

    首先,记得导入jquery.js文件. json内容: var obj123=[        {"option":"2,3,9,14,19,24,32",&q ...

  2. 软件工程第六组U-Helpβ版使用说明

    软件工程第六组U-Helpβ版使用说明 U-help ——告别取件烦恼 produced by 六扇门 源代码下载地址:https://github.com/U-Help/Version-1.0 安装 ...

  3. protocols - 协议定义文件

    描述 该文件为普通 ASCII 文件,它描述了 TCP/IP 子系统中各类 DARPA internet 协议族.你应该参考这个文件, 而不是使用 ARPA 的 include 文件中的号码, 更不必 ...

  4. Codecraft-17 and Codeforces Round #391 - A

    题目链接:http://codeforces.com/contest/757/problem/A 题意:给定一个字符串,问你从这个字符串中选出一些字符然后重新排序后最多能组成多少个 Bulbasaur ...

  5. 洛谷P3830 随机树(SHOI2012)概率期望DP

    题意:中文题,按照题目要求的二叉树生成方式,问(1)叶平均深度 (2)树平均深度 解法:这道题看完题之后完全没头绪,无奈看题解果然不是我能想到的qwq.题解参考https://blog.csdn.ne ...

  6. 前端学习(三十八)vue(笔记)

    Angular+Vue+React    Vue性能最好,Vue最轻=======================================================Angular     ...

  7. Sass值列表

    所谓值列表 (lists) 是指 Sass 如何处理 CSS 中: margin: 10px 15px 0 0 或者: font-face: Helvetica, Arial, sans-serif ...

  8. mangodb语句

    { field: { $exists: <boolean> } }

  9. mybatis基本查询

    <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapper PUBLIC "-/ ...

  10. UVA11540 Sultan's Chandelier Burnside 引理 + DP

    题目传送门 https://vjudge.net/problem/UVA-11540 https://uva.onlinejudge.org/index.php?option=com_onlineju ...