首页 技术 正文
技术 2022年11月14日
0 收藏 713 点赞 2,620 浏览 1517 个字

You are given two integers nn and mm . Calculate the number of pairs of arrays (a,b)(a,b) such that:

  • the length of both arrays is equal to mm ;
  • each element of each array is an integer between 11 and nn (inclusive);
  • ai≤biai≤bi for any index ii from 11 to mm ;
  • array aa is sorted in non-descending order;
  • array bb is sorted in non-ascending order.

As the result can be very large, you should print it modulo 109+7109+7 .

Input

The only line contains two integers nn and mm (1≤n≤10001≤n≤1000 , 1≤m≤101≤m≤10 ).

Output

Print one integer – the number of arrays aa and bb satisfying the conditions described above modulo 109+7109+7 .

ExamplesInput

 

2 2

Output

 

5

Input

 

10 1

Output

 

55

Input

 

723 9

Output

 

157557417由题意可知,这个题所求的两个序列实际上可以合并成一个,将递增序列的头部接到递减序列的尾部,所得一个长为2m的序列。原问题可以转化为求范围1到n的2m个数组成的递增序列的个数(一个序列里可以有两个重复的数)。官方题解直接用Python+组合数公式
from math import factorial as fact
mod = 10**9 + 7def C(n, k):
return fact(n) // (fact(k) * fact(n - k))n, m = map(int, input().split())
print(C(n + 2*m - 1, 2*m) % mod)

从原理入手,当这2m个数里有i个数不相同时,先从n个位置里用C(n,i)算出当前有几种选法,接下来有2m-i个数是和刚刚选出来的序列的部分数相同,可以看作同球入不同盒问题直接应用公式计算即可,每次循环更新ans。题目要求取模,这里借鉴了https://www.csdn.net/gather_2b/NtzaIgxsNzQtYmxvZwO0O0OO0O0O.html里组合数快速取模的知识。

#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
long long n,m;
int inv(int a)
{
return a==?:(long long)(MOD-MOD/a)*inv(MOD%a)%MOD;
}
long long C(long long n,long long m)//组合数快速取模
{
if(m<)return ;
if(n<m)return ;
if(m>n-m)m=n-m;
long long up=,down=;
long long i;
for(i=;i<m;i++)
{
up=up*(n-i)%MOD;
down=down*(i+)%MOD;
}
return up*inv(down)%MOD;
}
int main()
{
cin>>n>>m;
int i;
long long ans=;
for(i=*m;i>=;i--)//有i个不同的数
{
if(i>n)continue;
ans=(ans+C(n,i)*/*同球入不同盒 2*m-i入i */ C(*m-i+i-,i-))%MOD;
}
printf("%lld",ans);
return ;
}

    					
下一篇: leetcode 0210
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,031
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,860