Killer Names
来源:互联网 发布:怎样提高淘宝店排名 编辑:程序博客网 时间:2024/05/01 08:15
1011-Killer Names
*-HDU-2017 Multi-University Training Contest - Team 8*
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 exactly n characters, while each character is chosen from an alphabet of size m. It appears that there are m^{2n} 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.
Input
The First line of the input contains an integer T (T\le 10), denoting the number of test cases.
Each test case contains two integers n and m (1\le n, m \le 2000).
Output
For each test case, output one line containing the maximum number of clones Vader can create.
Output the answer \ mod\ 10^9+7
Sample Input
2
3 2
2 3
Sample Output
2
18
Solution
Permulation+Stiriling
题意:起名。姓、名各有n个位,共有m个字符可以选择。姓与名不可以含有相同字母。问总共有多少起名方式。n,m<=2000。
首先给姓选择字符,分别可选i=1,2,..,.m-1种。考虑到字符应当放到具体位上去,分别乘S[n][i]。
相应地,名可有j=1..m-1,1..m-2,…,1种。各自乘上S[n][j]再求和,将和与S[n][i]相乘。
累加。
注意对1e9+7取模。
Code
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int mx = 2010;const ll mod = 1e9+7;int T,m,n;ll ans,S[mx][mx],s,t,f[mx],tmp;int c[2051][2051];int main() { for (int i=0; i<=2002; i++) for (int j=0; j<=i; j++) if (j==0||i==j) c[i][j]=1; else c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod; f[1]=1; for (int i=2; i<2001; ++i) f[i]=f[i-1]*i%mod; for (int i=0; i<2001; ++i) S[i][i]=1; for (int i=0; i<2001; ++i) { for (int j=1; j<i; ++j) { if (i==j) continue; S[i][j]=(S[i-1][j]*j+S[i-1][j-1])%mod; } } scanf("%d",&T); while (T--) { scanf("%d%d",&n,&m); ans=0; for (int i=1; i<=min(m-1,n); ++i) { s=0; t=((c[m][i]%mod)*S[n][i])%mod; t=t*f[i]%mod; for (int j=1; j<=min(m-i,n); ++j) { tmp=f[j]*c[m-i][j]%mod; s=(s+tmp*S[n][j])%mod; } ans=(ans+(s*t))%mod; } printf("%I64d\n",ans); } return 0;}
- Killer Names
- HDU 6143 Killer Names
- HDU-6140 Killer Names
- HDU6143-Killer Names
- hdu--6143--Killer Names
- hdu 6143 Killer Names
- hdu6143-Killer Names
- HDU6143 Killer Names
- hdu 6143 Killer Names
- HDU 6143 Killer Names
- hdu 6143 Killer Names
- HDU 6143 Killer Names
- HDU --6143 Killer Names
- hdu6143 Killer Names
- Killer Names (HDU6143 17多校赛)
- hdu 6143 Killer Names dp
- Killer Names(hdu 6143)
- Killer Names(HDU 6143)
- 滚动显示置顶按钮
- HDU Find the hotel
- 安装篇 03. 安装到服务器 ❀ Windows Server 2016
- POJ 排序 单向队列的应用
- Redis设实
- Killer Names
- 对于oracle数据库中怎么查看clob类型的值
- 约瑟夫问题I/II
- leetcode 39. Combination Sum
- hashCode 以及hashMap排序
- 地图二三维联动原理
- hdu 2018 母牛的故事 动态规划--简单
- mysql数据库备份
- qwt横轴为时间轴,纵轴为随机数