The Monkey King(hdu5201)
The Monkey King
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 487 Accepted Submission(s): 166
everyone known, The Monkey King is Son Goku. He and his offspring live
in Mountain of Flowers and Fruits. One day, his sons get n peaches. And there are m monkeys (including GoKu), they are numbered from 1 to m,
GoKu’s number is 1. GoKu wants to distribute these peaches to
themselves. Since GoKu is the King, so he must get the most peach. GoKu
wants to know how many different ways he can distribute these peaches.
For example n=2, m=3, there is only one way to distribute these peach: 2
0 0.
When given n and m,
you are expected to calculate how many different ways GoKu can
distribute these peaches. Answer may be very large, output the answer
modular 1000000007 instead.
In the next T lines, each line contains n and m which is mentioned above.
[Technical Specification]
All input items are integers.
1≤T≤25
1≤n,m≤100000
See the sample for more details.
For the second case, there are five ways. They are
2 1 0 0 0
2 0 1 0 0
2 0 0 1 0
2 0 0 0 1
3 0 0 0 0
1 #include <iostream>
2 #include<algorithm>
3 #include<string.h>
4 #include<queue>
5 #include<math.h>
6 #include<set>
7 #include<stdio.h>
8 using namespace std;
9 typedef long long LL;
10 LL N[200010];
11 LL NN[200010];
12 const LL mod = 1e9+7;
13 LL quick(LL n,LL m);
14 LL C(LL n,LL m);
15 int main(void)
16 {
17 int n;
18 scanf("%d",&n);
19 N[0] = 1;
20 int i,j;NN[0] = 1;
21 for(i = 1; i <= 200005; i++)
22 {
23 N[i] = N[i-1]*(LL)i%mod;
24 NN[i] = quick(N[i],mod-2);
25 }
26 //printf("%lld\n",quick(6,mod-2));
27 while(n--)
28 {
29 int m,k;
30 scanf("%d %d",&m,&k);
31 LL sum = 0;
32 if(k == 1)
33 printf("%d\n",k);
34 else
35 {
36 for(i = m; i >= 1; i--)
37 {
38 LL x = m-i;
39 LL y = k-1;
40 LL an = C(x+y-1,y-1);
41 for(j = 1; j <= k-1&&(LL)(j+1)*(LL)i<= m; j++)
42 {
43 x = k-1;
44 y = j;
45 LL akk = C(x,y);
46 LL ab = m-(LL)(j+1)*(LL)i;
47 ab = ab+k-2;
48 LL bk = C(ab,k-2);
49 if(j%2)
50 an = an-bk*akk%mod;
51 else an+=(bk*akk)%mod;
52 an = an%mod;
53 }
54 sum = (sum+an)%mod;
55 }
56 printf("%lld\n",(sum%mod+mod)%mod);
57 }
58 }
59 }
60 LL C(LL n,LL m)
61 {
62 LL ni = NN[n-m]*NN[m]%mod;
63 return ni*N[n]%mod;
64 }
65 LL quick(LL n,LL m)
66 {
67 LL ask = 1;
68 n%=mod;
69 while(m)
70 {
71 if(m&1)
72 ask = ask*n%mod;
73 n = n*n%mod;
74 m/=2;
75 }
76 return ask;
77 }
The Monkey King(hdu5201)的更多相关文章
- ZOJ 2334 Monkey King
并查集+左偏树.....合并的时候用左偏树,合并结束后吧父结点全部定成树的根节点,保证任意两个猴子都可以通过Find找到最厉害的猴子 Monkey King ...
- 数据结构(左偏树):HDU 1512 Monkey King
Monkey King Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- P1456 Monkey King
题目地址:P1456 Monkey King 一道挺模板的左偏树题 不会左偏树?看论文打模板,完了之后再回来吧 然后你发现看完论文打完模板之后就可以A掉这道题不用回来了 细节见代码 #include ...
- HDU - 5201 :The Monkey King (组合数 & 容斥)
As everyone known, The Monkey King is Son Goku. He and his offspring live in Mountain of Flowers and ...
- Monkey King(左偏树 可并堆)
我们知道如果要我们给一个序列排序,按照某种大小顺序关系,我们很容易想到优先队列,的确很方便,但是优先队列也有解决不了的问题,当题目要求你把两个优先队列合并的时候,这就实现不了了 优先队列只有插入 删除 ...
- 1512 Monkey King
Monkey King Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- HDU-5201 The Monkey King
题目描述 \(m\)个猴子分\(n\)个桃,要求第一个猴子的桃数严格大于其他猴子,问有多少种分法对\(1e9+7取模(\%1e9+7)\) Input \(1≤T≤25 ,1≤n,m≤100000\) ...
- hdu1512 Monkey King
Problem Description Once in a forest, there lived N aggressive monkeys. At the beginning, they each ...
- [Monkey King]
题目描述 在一个森林里住着N(N<=10000)只猴子.在一开始,他们是互不认识的.但是随着时间的推移,猴子们少不了争斗,但那只会发生在互不认识(认识具有传递性)的两只猴子之间.争斗时,两只猴子 ...
随机推荐
- 20-Integer to Roman-Leetcode
比较简单的思路:用map存放各个位的数字到罗马字符的映射 然后从个位依次遍历高位加上映射即可. Given an integer, convert it to a roman numeral. Inp ...
- 学习java第十九天
一.今日收获 1.java完全学习手册第三章算法的3.2排序,比较了跟c语言排序上的不同 2.观看哔哩哔哩上的教学视频 二.今日问题 1.快速排序法的运行调试多次 2.哔哩哔哩教学视频的一些术语不太理 ...
- 日常Java 2021/9/23
练习使用Math.random函数,以及JOptionPane.showMessageDialog(null,"字符串","Results",JOptionPa ...
- Hive(十三)【Hive on Spark 部署搭建】
Hive on Spark 官网详情:https://cwiki.apache.org//confluence/display/Hive/Hive+on+Spark:+Getting+Started ...
- [php反序列化] CVE-2020-15148(Yii2 反序列化漏洞) 漏洞复现
漏洞影响范围 Yii2 < 2.0.38 环境搭建 Yii2.0.37 漏洞分析 首先定位到漏洞起始点 为什么是这儿?我们该怎么发现是某个类的某个函数?为什么不是其他函数? 一般是__destr ...
- electron搭建开发环境
环境:windons10, nodev14.17.1, vscode md a_star cd a_star npm i -g yarn yarn config set ELECTRON_MIRROR ...
- Spring Boot下使用拦截器
Spring Boot对于原来在配置文件配置的内容,现在全部体现在一个类中,该类需要继承自WebMvcConfigurationSupport类,并使用@Configuration进行注解,表示该类为 ...
- 【Java 基础】java 创建对象时重写方法
TransactionLock mockLock = new TransactionLock() { public boolean lock(String id) { return true; } p ...
- mysq中char,varchar,text的区别
mysql5.0.3以后,n都表示字符数(varchar(n)) 检索效率 char > varchar > text 当varchar长度超过255之后,跟text一致,但是设置varc ...
- ssm中的模糊查询
1.首先是数据层接口协议 public List<User> looks(String uname); 2.数据层实现 <select id="looks" re ...