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

Educational Codeforces Round 80 C. Two Arrays(组合数快速取模)的更多相关文章

  1. Educational Codeforces Round 80 (Rated for Div. 2)

    A. Deadline 题目链接:https://codeforces.com/contest/1288/problem/A 题意: 给你一个 N 和 D,问是否存在一个 X , 使得 $x+\lce ...

  2. Educational Codeforces Round 80 A-E简要题解

    contest链接:https://codeforces.com/contest/1288 A. Deadline 题意:略 思路:根据题意 x + [d/(x+1)] 需要找到一个x使得上式小于等于 ...

  3. Educational Codeforces Round 80 (Rated for Div. 2)部分题解

    A. Deadline 题目链接 题目大意 给你\(n,d\)两个数,问是否存在\(x\)使得\(x+\frac{d}{x+1}\leq n\),其中\(\frac{d}{x+1}\)向上取整. 解题 ...

  4. Educational Codeforces Round 80 (Rated for Div. 2)D E

    D枚举子集 题:https://codeforces.com/contest/1288/problem/D题意:给定n个序列,每个序列m个数,求第i个和第j个序列组成b序列,b序列=max(a[i][ ...

  5. Educational Codeforces Round 80 D E

    A了三题,rk1000左右应该可以上分啦,开

  6. Educational Codeforces Round 80 (Rated for Div. 2) E. Messenger Simulator

    可以推出 min[i]要么是i要么是1,当a序列中存在这个数是1 max[i]的话就比较麻烦了 首先对于i来说,如果还没有被提到第一位的话,他的max可由他后面的这部分序列中 j>=i 的不同数 ...

  7. Educational Codeforces Round 80 (Rated for Div. 2)(A-E)

    C D E 这三道题感觉挺好       决定程序是否能通过优化在要求的时间内完成,程序运行时间为t,你可以选择花X天来优化,优化后程序的运行时间为t/(x+1)取上整,花费的时间为程序运行时间加上优 ...

  8. Educational Codeforces Round 80 (Rated for Div. 2)E(树状数组,模拟,思维)

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ],mx[],a[],pos[],sum ...

  9. Educational Codeforces Round 80 (Rated for Div. 2)D(二分答案,状压检验)

    这题1<<M为255,可以logN二分答案后,N*M扫一遍表把N行数据转化为一个小于等于255的数字,再255^2检验答案(比扫一遍表复杂度低),复杂度约为N*M*logN #define ...

随机推荐

  1. webpack4.41.0配置一(基础配置webpack文件,入口出口,实现打包)

    1.查看node.js版本.npm版本和webpack版本(使用webpack4时,请确保node.js的版本>=8.9.4) 2.我先重新卸载了webpack和webpack-cli(全局) ...

  2. centos7 命令 对比 cenots6 命令

    1)  列出所有service开机启动项 centos 7 systemctl list-unit-files |grep enabled centos 6 chkconfig --list|grep ...

  3. 解析python 生产/消费者模型实现过程

    1.多线程实现 import threadingimport queueimport logginglogging.basicConfig(level = logging.INFO,format = ...

  4. SCROLLINFO结构详解

    在刚开始使用SCROLLINFO结构时感觉很不顺手,尤其其中的成员fMask理解不太深刻,经过查询资料才理解一二. 在使用滚动条功能时,如果要设置它的范围和位置可以用以前的函数,例如:SetScrol ...

  5. spring_boot 中通过PageHelper分页

    1. 第一步 导入pom.xml依赖 <!--PageHelper模版--> <!--PageHelper模版--> <dependency> <groupI ...

  6. tomcat查看当前内存

    查看运行中的tomcat内存非常简单,只需运行一下此界面就可以看到. <html> <head><meta http-equiv="Content-Type&q ...

  7. Git - 后续

    1. 概述 现在讲了这些, 也就能应付一下日常的单机操作 后续大概会讲这些内容 分之间的 merge 本地仓库与远程仓库的互动

  8. 连接查询:inner join,left join,right join

    感谢原创:https://blog.csdn.net/plg17/article/details/78758593 准备工作: 1)新建两张表a_table和b_table: create table ...

  9. Linux Ubuntu运行线程程序出现undefined reference to ‘pthread_create’和undefined reference to ‘pthread_join’错误。

    Linux Ubuntu运行线程程序出现undefined reference to ‘pthread_create’和undefined reference to ‘pthread_join’错误. ...

  10. Fiddler修改http请求响应简单实例

    Fiddler是一个http调试代理,它能够记录并检查所有你的电脑和互联网之间的http通讯. 主要功能 设置断点,查看Fiddle说有的进出的数据(指cookie,html,js,css等文件,这些 ...