牛客多校第一场A

链接:https://www.nowcoder.com/acm/contest/139/A
来源:牛客网
 

题目描述

Count the number of n x m matrices A satisfying the following condition modulo (10^9+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 ≤ 10^3
* The number of test cases does not exceed 10^5

题解:

 

定理链接:http://www.cnblogs.com/jszkc/p/7309468.html

#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const int maxn = 1 << 11;
const int MOD = 1E9 +7;
ll C[maxn][maxn];
void init()
{
    C[0][0] = 1;
    for(int i = 1; i < maxn; i ++) {
        C[i][0] = 1;
        for(int j = 1; j <= i; j ++) {
            C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
            C[i][j] %= MOD;
        }
    }
}
 
 
int main()
{
    ios::sync_with_stdio(false), cin.tie(0);
    init();
    ll n, m;
    while(cin >> n >> m) {
        ll res = C[n+m][n] * C[n+m][n] % MOD;
        ll t = C[n+m][n-1] * C[n+m][m-1] % MOD;
        res -= t;
        cout << (res % MOD + MOD) % MOD << '\n';
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值