Educational Codeforces Round 80 C. Two Arrays(组合数快速取模)
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 .
The only line contains two integers nn and mm (1≤n≤10001≤n≤1000 , 1≤m≤101≤m≤10 ).
Print one integer – the number of arrays aa and bb satisfying the conditions described above modulo 109+7109+7 .
2 2
5
10 1
55
723 9
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(组合数快速取模)的更多相关文章
- Educational Codeforces Round 80 (Rated for Div. 2)
A. Deadline 题目链接:https://codeforces.com/contest/1288/problem/A 题意: 给你一个 N 和 D,问是否存在一个 X , 使得 $x+\lce ...
- Educational Codeforces Round 80 A-E简要题解
contest链接:https://codeforces.com/contest/1288 A. Deadline 题意:略 思路:根据题意 x + [d/(x+1)] 需要找到一个x使得上式小于等于 ...
- Educational Codeforces Round 80 (Rated for Div. 2)部分题解
A. Deadline 题目链接 题目大意 给你\(n,d\)两个数,问是否存在\(x\)使得\(x+\frac{d}{x+1}\leq n\),其中\(\frac{d}{x+1}\)向上取整. 解题 ...
- 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][ ...
- Educational Codeforces Round 80 D E
A了三题,rk1000左右应该可以上分啦,开
- Educational Codeforces Round 80 (Rated for Div. 2) E. Messenger Simulator
可以推出 min[i]要么是i要么是1,当a序列中存在这个数是1 max[i]的话就比较麻烦了 首先对于i来说,如果还没有被提到第一位的话,他的max可由他后面的这部分序列中 j>=i 的不同数 ...
- Educational Codeforces Round 80 (Rated for Div. 2)(A-E)
C D E 这三道题感觉挺好 决定程序是否能通过优化在要求的时间内完成,程序运行时间为t,你可以选择花X天来优化,优化后程序的运行时间为t/(x+1)取上整,花费的时间为程序运行时间加上优 ...
- Educational Codeforces Round 80 (Rated for Div. 2)E(树状数组,模拟,思维)
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ],mx[],a[],pos[],sum ...
- Educational Codeforces Round 80 (Rated for Div. 2)D(二分答案,状压检验)
这题1<<M为255,可以logN二分答案后,N*M扫一遍表把N行数据转化为一个小于等于255的数字,再255^2检验答案(比扫一遍表复杂度低),复杂度约为N*M*logN #define ...
随机推荐
- Docker - ubuntu 镜像安装网络工具
概述 给 ubuntu 镜像, 安装一些基本的网络工具 背景 尝试学习的时候, 需要检测网络的连通性 没有这些工具, 绕了不少弯路 工具们 ping ip a 环境 docker 18.09 ubun ...
- MyBatis-config.xml示例
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC ...
- Windows server 2012文件服务器配置
文件服务器的管理 Windows server 2012提供了易于使用的管理工具,让系统管理员更有效的管理服务器的资源. 安装文件服务器管理工具 添加角色-安装管理器 安装完成后直接可以在工具中打 ...
- 计算几何-UVa10652
This article is made by Jason-Cow.Welcome to reprint.But please post the article's address. 题意见白书,P2 ...
- 计算几何-Ang-Rad-Vector
This article is made by Jason-Cow.Welcome to reprint.But please post the article's address. 旋转,跳跃,梦境 ...
- bugku 好多压缩包
https://www.cnblogs.com/WangAoBo/p/6951160.html
- 一起学Netty(一)之HelloWorld,可以聊天的小程序哦
转自于:http://blog.csdn.net/linuu/article/details/51306480
- 数据库程序接口——JDBC——API解读第一篇——建立连接的核心对象
结构图 核心对象 Driver Java通过Driver接口表示驱动,每种类型的数据库通过实现Driver接口提供自己的Driver实现类. Driver由属性,操作,事件三部分组成. 属性 公共属性 ...
- C语言中调用运行python程序
C语言中调用运行python程序: Python代码如下: 创建test.py. #!/usr/bin/python3 #test.py import sys x = ]) print x*x 注意: ...
- 题解 SP7579 YOKOF - Power Calculus
SP7579 YOKOF - Power Calculus 迭代加深搜索 DFS每次选定一个分支,不断深入,直至到达递归边界才回溯.这种策略带有一定的缺陷.试想以下情况:搜索树每个节点的分支数目非常多 ...