链接: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. saltstack的高级管理

    一.saltstack的状态管理 状态管理官网: https://www.unixhot.com/docs/saltstack/ref/states/all/index.html 1)状态分析 [ro ...

  2. 20180209-shutil模块

    下面讲解shutil模块的相关操作: 1.shutil.copyfileobj(fsrc, fdst, length=16*1024) 将fsrc文件内容拷贝到fdst文件中,length是指一次拷贝 ...

  3. maven项目引入spring boot依赖之后filter不生效的问题

    maven的filtering没有起作用,没有把占位符给替换掉.(大家可以执行mvn clean package,看看打包后的jar里面的application.properties文件,是否有替换占 ...

  4. python3使用print打印带颜色的字符串

    一.实现过程 终端的字符颜色是用转义序列控制的,是文本模式下的系统显示功能,和具体的语言无关 转义序列是以ESC开头,即用\033来完成(ESC的ASCII码用十进制表示是27,用八进制表示就是033 ...

  5. HTML基础 img标签 做一个图库

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  6. Python 分段利润提成

    题目:企业发放的奖金根据利润提成.利润(I)低于或等于10万元时,奖金可提10%:利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%:20万到40万之 ...

  7. Spring---Spring Aware

    1.概述 1.1.Spring中的  所有Bean  对Spring容器的存在  是没有意识的(即你可以将容器换成别的容器,这样使用容器与Bean之间的耦合度很低): 但在实际项目中,不可避免的要用到 ...

  8. vue项目放在IE上页面空白的问题

    Babel是一个广泛使用的转码器,可以将ES6代码转为ES5代码 1.npm install babel-polyfill --save 2.main.js中引入 import 'babel-poly ...

  9. 【leetcode】609. Find Duplicate File in System

    题目如下: Given a list of directory info including directory path, and all the files with contents in th ...

  10. Ubuntu Visual code安装与使用

    1.直接启动软件中心,输入visual studio code,点击install即可,千万千万不要去装逼搞什么linux指令安装,死都不知道怎么死的 2.Visual code是以文件夹为工程目录的 ...