hdu6143Killer Names(第八场容斥组合数)
来源:互联网 发布:android防淘宝评论 编辑:程序博客网 时间:2024/06/05 21:53
Killer Names
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1187 Accepted Submission(s): 581
Problem Description
> Galen Marek, codenamed Starkiller, was a male Human apprentice of the Sith Lord Darth Vader. A powerful Force-user who lived during the era of the Galactic Empire, Marek originated from the Wookiee home planet of Kashyyyk as the sole offspring of two Jedi Knights—Mallie and Kento Marek—who deserted the Jedi Order during the Clone Wars. Following the death of his mother, the young Marek's father was killed in battle by Darth Vader. Though only a child, Marek possessed an exceptionally strong connection to the Force that the Dark Lord of the Sith sought to exploit.
>
> When Marek died in 2 BBY, shortly after the formation of the Alliance, Vader endeavored to recreate his disciple by utilizing the cloning technologies of the planet Kamino. The accelerated cloning process—an enhanced version of the Kaminoan method which allowed for a rapid growth rate within its subjects—was initially imperfect and many clones were too unstable to take Marek's place as the Dark Lord's new apprentice. After months of failure, one particular clone impressed Vader enough for him to hope that this version might become the first success. But as with the others, he inherited Marek's power and skills at the cost of receiving his emotions as well, a side effect of memory flashes used in the training process.
>
> — Wookieepedia
Darth Vader is finally able to stably clone the most powerful soilder in the galaxy: the Starkiller. It is the time of the final strike to destroy the Jedi remnants hidden in every corner of the galaxy.
However, as the clone army is growing, giving them names becomes a trouble. A clone of Starkiller will be given a two-word name, a first name and a last name. Both the first name and the last name have exactlyn characters, while each character is chosen from an alphabet of size m . It appears that there are m2n possible names to be used.
Though the clone process succeeded, the moods of Starkiller clones seem not quite stable. Once an unsatisfactory name is given, a clone will become unstable and will try to fight against his own master. A name is safe if and only if no character appears in both the first name and the last name.
Since no two clones can share a name, Darth Vader would like to know the maximum number of clones he is able to create.
>
> When Marek died in 2 BBY, shortly after the formation of the Alliance, Vader endeavored to recreate his disciple by utilizing the cloning technologies of the planet Kamino. The accelerated cloning process—an enhanced version of the Kaminoan method which allowed for a rapid growth rate within its subjects—was initially imperfect and many clones were too unstable to take Marek's place as the Dark Lord's new apprentice. After months of failure, one particular clone impressed Vader enough for him to hope that this version might become the first success. But as with the others, he inherited Marek's power and skills at the cost of receiving his emotions as well, a side effect of memory flashes used in the training process.
>
> — Wookieepedia
Darth Vader is finally able to stably clone the most powerful soilder in the galaxy: the Starkiller. It is the time of the final strike to destroy the Jedi remnants hidden in every corner of the galaxy.
However, as the clone army is growing, giving them names becomes a trouble. A clone of Starkiller will be given a two-word name, a first name and a last name. Both the first name and the last name have exactly
Though the clone process succeeded, the moods of Starkiller clones seem not quite stable. Once an unsatisfactory name is given, a clone will become unstable and will try to fight against his own master. A name is safe if and only if no character appears in both the first name and the last name.
Since no two clones can share a name, Darth Vader would like to know the maximum number of clones he is able to create.
Input
The First line of the input contains an integer T (T≤10 ), denoting the number of test cases.
Each test case contains two integersn and m (1≤n,m≤2000 ).
Each test case contains two integers
Output
For each test case, output one line containing the maximum number of clones Vader can create.
Output the answer mod 109+7
Output the answer
Sample Input
23 22 3
Sample Output
2 18
Source
2017 Multi-University Training Contest - Team 8
题意:m种字符放在两个长度为n的名,字中,问让两边颜色不同有多少种存放方式,假设前n个名为i种字符,那么后面的n字则有字符m-i种,这样就变成了容斥问题:如果n个长度用x个字符表达,那就相当于n个不同小球放在x个不同的盒子里。设其结果为f(x),那么f(x) = x ^ n - C(x, 1) * f(x - 1) - C(x, 2) * f(x - 2) …… - C(x, x - 1) * f(1). 然后就是枚举所有的x,统计其和
#include<cstdio>#define mod 1000000007#include<iostream>using namespace std;typedef long long LL;LL C[2005][2005];LL cal[2005];LL n,m;LL quickM(LL a, LL b){ LL ans = 1; while(b) { if(b & 1) ans = ans * a % mod; b >>= 1; a = a * a % mod; } return ans;}void init(){ C[0][0] = 1; for(int i = 1; i <= 2001; i++)///这里只算到2001,到2005超时。。无法理解 { C[i][0] = 1; for(int j = 1; j <= i; j++) { C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod; } }}void calt()///算出i^n-∑C(i,j)*j^n,也就是i个字符存在n个名字中的存放方式{ for(LL i = 1; i <= n; i++) { cal[i] = quickM(i, n); for(int j = 1; j < i; j++) { cal[i] -= C[i][j] * cal[j] % mod; cal[i] = (cal[i] + mod ) % mod; } }}int main(){ init(); int T; scanf("%d", &T); while(T--) { scanf("%lld%lld", &n, &m); LL ans = 0; calt(); //cout<<"cal-->"<<cal[5]<<endl; for(LL i = 1; i <= n; i++) { if(i >= m) break; for(LL j = 1; j <= n; j++) { if(j > m - i) break; ans += C[m][i] * cal[i] % mod * cal[j] % mod * C[m - i][j] % mod;///名和字分别乘起来,统计总数 //cout<<"ans-->"<<C[m][i]<<C[m-i][j]<<endl; ans %= mod; } } printf("%lld\n", ans); } return 0;}
阅读全文
0 0
- hdu6143Killer Names(第八场容斥组合数)
- hdu6143Killer Names(组合递推+容斥原理)
- HDU6143Killer Names
- hdu 6143 Killer Names (组合数,递推)
- HDU 6143 Killer Names(组合数+第二类Stirling数)
- HDU 6143 Killer Names 组合数+(容斥/第二类Stirling数)
- hdu6143 Killer Names 2017多校第八场1011 组合数学
- HDU 6143 Killer Names(组合数学 递推 17多校第八场)
- hdu6143 Killer Names(strling数)
- hdu 6143 Killer Names (2017多校第八场)
- 第八届山东省赛 C sdut 3895 fireworks(组合数+逆元)
- 山东省第八届 ACM 省赛 fireworks (组合数+逆元)
- 第八届福建省大学生程序设计竞赛-K Wand(错位+组合数)
- hdu 6143 Killer Names(组合计数)(DP)
- HDU 6143 Killer Names(容斥+组合)
- hdu6143-多校8&三种方法-组合数|递推|容斥-Killer Names
- 第八届山东acm省赛 C题 fireworks (组合数)
- HDU6143 Killer Names 【数学+组合】
- HDU
- 前端中用手机拍照压缩,上传图片压缩
- 从iOS 使用jenkins 自动化打包说去
- dubbo服务接口开发者必备调试利器,你值得拥有
- android : update.zip包的制作
- hdu6143Killer Names(第八场容斥组合数)
- 文件夹下有两个或者多个lds,GCC采用那个连接脚本?
- 使用原生js创建ajax请求
- 2018网易校招编程题(5)独立的小易
- GetBuffer与ReleaseBuffer的用法,CString剖析
- Lua认为false和nil为假,true和非nil为真。 要注意的是Lua中 0 为 true
- 如何处理java高并发问题---之页面静态化
- 【多校训练】hdu 6066 RXD's date
- web前端