题目来源

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. Error【0007】:zabbix中因为curl版本过低而无法发送邮件

    1. 错误背景 在centos6.5上,源码部署zabbix最新版本zabbix-3.2.14.部署后之后,在配置邮件发送报警时出错 2. 错误提示 3. 原因分析 从网上检索的结果是说,系统中的cu ...

  2. 开发CMDB系统

    背景: 在现网环境中服务器多了每天服务器的配置 情况我们很难记住,当某台服务器硬件配置变化后可以第一时间了解,某台服务器出现问题时可以快速定位机架位置,之前都是excel文档,要查某项数据时极不方便. ...

  3. Centos下SVN环境部署记录

    大多数情况下,我们日常工作中用的版本控制系统都会选择分布式的Git,它相比于集中式的SVN有很多优势.但是有些项目软件基于自身限制,可能只支持SVN做工程同步.废话就不多说了,下面记录下SVN的部署和 ...

  4. php 中self,this的区别和实地操作

    面向对象编程(OOP,Object OrientedProgramming)现已经成为编程人员的一项基本技能.利用OOP的思想进行PHP的高级编程,对于提高PHP编程能力和规划web开发构架都是很有意 ...

  5. PairProject 总结

    结对编程人员:张迎春,赵梓皓.下面是我们一起编程的照片. 结对编程的优点: 首先,结对编程的目的是为了减少编程的错误,在编程的时候,大家一起检查错误,一起分析有没有更加合理的编写方法,所以这是结对编程 ...

  6. 同步手绘板——android端下笔后颜色变化

    实现效果 : 在设计之初我们以为是改变笔线条的粗细来实现类似效果,后来通过找其他相关软件比对发现是不改变线条的粗细,通过改变透明度实现下笔后颜色的渐变,虽然已实现,但渐变效果很一般,不流畅,算法还待优 ...

  7. beta 答辩总结

    评审表 编号 团队名称 项目名称 格式 内容 PPT 演讲 答辩 总分/100 1 天机组 指尖加密 14 13 13 13 13 66 2 PMS Your eyes 14 14 17 14 15 ...

  8. ppm\℃是什么意思/

    转自http://www.zybang.com/question/b158a106b4e39d8fdb2b93fd3777a00f.html 在基准电压的数据手册里,我们会找到一个描述基准性能的直流参 ...

  9. 实战框架ABP

    abp及实战框架概述 接触abp也快一年了,有过大半年的abp项目开发经验,目前项目中所用的abp框架版本为0.10.3,最新的abp框架已经到了1.4,并且支持了asp.net core.关于abp ...

  10. 终端curl调用jenkins自动化持续集成

    1.curlcurl是利用URL语法在命令行方式下工作的开源文件传输工具.它被广泛应用在Unix.多种Linux发行版中,并且有DOS和Win32.Win64下的移植版本. 1.1 获取url指向的页 ...