题目来源

The 2018 ACM-ICPC China JiangSu Provincial Programming Contest

35.4%

  • 1000ms
  • 65536K

Persona5

Persona5 is a famous video game.

In the game, you are going to build relationship with your friends.

You have N friends and each friends have his upper bound of relationship with you. Let's consider the ithi^{th}ith friend has the upper bound UiU_iUi​. At the beginning, the relationship with others are zero. In the game, each day you can select one person and increase the relationship with him by one. Notice that you can't select the person whose relationship with you has already reach its upper bound. If your relationship with others all reach the upper bound, the game ends.

It's obvious that the game will end at a fixed day regardless your everyday choices. Please calculate how many kinds of ways to end the game. Two ways are said to be different if and only if there exists one day you select the different friend in the two ways.

As the answer may be very large, you should output the answer mod 1000000007

Input Format

The input file contains several test cases, each of them as described below.

  • The first line of the input contains one integers N(1≤N≤1000000)(1 \le N \le 1000000)(1≤N≤1000000), giving the number of friends you have.
  • The second line contains NNN integers. The ithi^{th}ith integer represents UiU_iUi​(1≤Ui≤1000000)( 1 \le U_i \le 1000000)(1≤Ui​≤1000000), which means the upper bound with ithi^{th}ith friend. It's guarantee that the sum of UiU_iUi​ is no more than 1000000.

There are no more than 10 test cases.

Output Format

One line per case, an integer indicates the answer mod 1000000007.

样例输入

3
1 1 1
3
1 2 3

样例输出

6
60
题目大意:有n个朋友,开始和每个朋友的关系为0,给出每个朋友的关系上限,每天只能和一个朋友的关系度增加1,求有多少种方式能够和他们的关系都达到上限。
解题思路:这道题很明显就是高中数学里面的排列组合题,我们可以先忽略先后顺序,直接把每个关系度看成一个朋友然后去掉是同一朋友的关系度,本质就是多重集合的排列计数问题 令 sum=a(1)+a(2)+。。。+a(n) ,答案就是 sum!/a1!a2!...an! 需要先打表,预处理逆元跟阶乘,否则会超时 复杂度:O(nlogn)(预处理)
附上AC代码:
 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+;
const int mod=1e9+;
ll fac[maxn],facinv[maxn];
ll n,a[maxn]; ll qpow(ll a,ll b,ll p) //快速幂取模
{
ll res=;
while(b)
{
if(b&) res=res*a%p;
b>>=;
a=a*a%p;
}
return res;
} void init() //求出阶乘与逆元
{
fac[]=fac[]=facinv[]=facinv[]=;
for(int i=;i<maxn;i++)
{
fac[i]=fac[i-]*i%mod;
facinv[i]=facinv[i-]*qpow(i,mod-,mod)%mod;
}
} int main()
{
init();
while(cin>>n)
{
ll sum=;
ll ans=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
ans=ans*facinv[a[i]]%mod;
}
ans=ans*fac[sum]%mod;
printf("%d\n",ans);
}
return ;
}

求逆元参考博客:https://blog.csdn.net/baidu_35643793/article/details/75268911

The 2018 ACM-ICPC China JiangSu Provincial Programming Contest快速幂取模及求逆元的更多相关文章

  1. The 2018 ACM-ICPC China JiangSu Provincial Programming Contest J. Set

    Let's consider some math problems. JSZKC has a set A=A={1,2,...,N}. He defines a subset of A as 'Meo ...

  2. The 2018 ACM-ICPC China JiangSu Provincial Programming Contest I. T-shirt

    JSZKC is going to spend his vacation! His vacation has N days. Each day, he can choose a T-shirt to ...

  3. The 2018 ACM-ICPC China JiangSu Provincial Programming Contest(第六场)

    A Plague Inc Plague Inc. is a famous game, which player develop virus to ruin the world. JSZKC wants ...

  4. C.0689-The 2019 ICPC China Shaanxi Provincial Programming Contest

    We call a string as a 0689-string if this string only consists of digits '0', '6', '8' and '9'. Give ...

  5. B.Grid with Arrows-The 2019 ICPC China Shaanxi Provincial Programming Contest

    BaoBao has just found a grid with $n$ rows and $m$ columns in his left pocket, where the cell in the ...

  6. ACM ICPC, Damascus University Collegiate Programming Contest(2018) Solution

    A:Martadella Stikes Again 水. #include <bits/stdc++.h> using namespace std; #define ll long lon ...

  7. 计蒜客 39272.Tree-树链剖分(点权)+带修改区间异或和 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest E.) 2019ICPC西安邀请赛现场赛重现赛

    Tree Ming and Hong are playing a simple game called nim game. They have nn piles of stones numbered  ...

  8. 计蒜客 39280.Travel-二分+最短路dijkstra-二分过程中保存结果,因为二分完最后的不一定是结果 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest M.) 2019ICPC西安邀请赛现场赛重现赛

    Travel There are nn planets in the MOT galaxy, and each planet has a unique number from 1 \sim n1∼n. ...

  9. 计蒜客 39279.Swap-打表找规律 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest L.) 2019ICPC西安邀请赛现场赛重现赛

    Swap There is a sequence of numbers of length nn, and each number in the sequence is different. Ther ...

随机推荐

  1. [Deep-Learning-with-Python]GAN图片生成

    GAN 由Goodfellow等人于2014年引入的生成对抗网络(GAN)是用于学习图像潜在空间的VAE的替代方案.它们通过强制生成的图像在统计上几乎与真实图像几乎无法区分,从而能够生成相当逼真的合成 ...

  2. python语言程序设计?

    1, 别说了,我还是有几分蛋疼的.女朋友..计算机..唉 2, 今天把那几个练习写完吧? 3, 这个注释有啥用最前面的?? 4, 我在学完python后必须学完C和C++并开始离散数学和线代高数等全复 ...

  3. Ionic 入门与实战之第一章:Ionic 介绍与相关学习资源

    原文发表于我的技术博客 本文是「Ionic 入门与实战」系列连载的第一章,主要对 Ionic 的概念.发展历程.适配的移动平台等知识进行了介绍,并分享了 Ionic 相关的学习资源. 原文发表于我的技 ...

  4. ABAQUS粘弹性边界及地震荷载施加的简单实现(Matlab生成input文件)

    思路 粘弹性边界因为能够考虑地基辐射阻尼而使得结构抗震的计算结果更趋于合理,所以在需要考虑结构地基相互作用的结构抗震计算时,是较为常用的地基边界处理和地震荷载施加方法.而ABAQUS软件是经常用来进行 ...

  5. Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)-D- Array Restoration

    我们知道不满足的肯定是两边大中间小的,这样就用RMQ查询两个相同等值的区间内部最小值即可,注意边界条件 #include<bits/stdc++.h> #define x first #d ...

  6. React++ node.js ++SQL Sever ++MySQL++ python ++ php ++ java ++ c++ c#++ java ++ android ++ ios ++Linux+

    "C语言在它诞生的那个年代,是非常不错的语言,可惜没有OOP.当项目臃肿到一定程度,人类就不可控了. 为了弥补这个缺陷,C++诞生了.而为了应对各种情况,C++设计的大而全,太多复杂的特性, ...

  7. BugPhobia启程篇章:需求分析与功能定位

    0x01 :引言 If you weeped for the missing sunset, you would miss all the shining stars 我看着大巴缓缓的驶过街角,我躲在 ...

  8. linux内核分析ELF文件分析实践报告

  9. Linux内核分析作业第五周

    系统调用的三个层次(下) 一.给MenuOS增加time和time-asm命令 1.克隆并自动编译 MenuOS rm menu -rf 强制删除原menu文件 git clone https://g ...

  10. Linux内核第六节 20135332武西垚

    如何描述一个进程:进程描述符的数据结构: 如何创建一个进程:内核是如何执行的,以及新创建的进程从哪里开始执行: 使用gdb跟踪新进程的创建过程. 进程的描述 操作系统三大功能: 进程管理(最核心最基础 ...