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 .

Examples
Input

 
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 + 7 def 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 ;
}

最新文章

  1. Windows 8 下离线安装。net Framework 3.5
  2. Android课程---添加黑名单的练习(课堂讲解)
  3. 普通硬件就能破解GSM A5加密算法
  4. Eclipse取消设置项目默认空间
  5. 前端框架——AmazeUI学习
  6. JSON.parse()和JSON.stringify()(转载)
  7. SteamVR Unity工具包(VRTK)之概览和控制器事件
  8. [转]PLS-S-00201, identifier &#39;CALLDEMO.GET_EMPLOYEES&#39; must be declared 预编译错误原因及解决办法
  9. CPU/寄存器/内存
  10. Spring Web MVC(一)
  11. kotlin web开发教程【一】从零搭建kotlin与spring boot开发环境
  12. GoLand、Pycharm注册码
  13. linux下安装好mysql后,登录时提示libgcc_s.so.1 must be installed for pthread_cancel to work
  14. java学习之路--StringBuffer常见的功能和实例
  15. python学习笔记四——循环及冒泡排序
  16. Mysql 删除重复数据只保留id最小的
  17. Mybatis之trim标签的理解
  18. Redis持久化--RDB+AOF(转)
  19. tomcat之日志切割
  20. IE6 验证码刷新失败显示空白解决办法

热门文章

  1. 微服务监控平台获取网关(zuul)配置列表
  2. 在手机浏览器中判断App是否已安装
  3. js面向过程 分页功能
  4. Tex 一些命令
  5. pikachu平台搭建
  6. lamp与zabbix开机自启
  7. 路飞-自定义User表和Media配置
  8. html()和append()
  9. HDU 2586(LCA欧拉序和st表)
  10. 在linux里面ps -ef | grep tomcat 什么意思