2017多校8-1011killer name
来源:互联网 发布:java验证码过期怎么做 编辑:程序博客网 时间:2024/06/06 01:35
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 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.
Input
The First line of the input contains an integer T (T≤10), denoting the number of test cases.
Each test case contains two integers n and m (1≤n,m≤2000).
Output
For each test case, output one line containing the maximum number of clones Vader can create.
Output the answer mod 109+7
Sample Input
2
3 2
2 3
Sample Output
2
18
【题意】
__姓__ __名__ 每个长度为N,给你M个字符,问可以有几种不同的名字,限制条件是一个字符只能用在一边。mod1e9+7
【解法】
dp[i][j]是在长度为i的字段上恰好放j个字符的放法(不考虑顺序)。
所以dp[i][j]可以从dp[i-1][j-1]和dp[i-1][j]推得。前者表示新加入的字符是之前没有出现过的,只有一种可能,后者表示放入一种之前已经出现过的字符,则有j种可能性。
所以
dp[i][j]=((j*dp[i-1][j])%mod+dp[i-1][j-1])%mod;
另外,在m中选取j个字符,所以要乘C(j,m),考虑到顺序问题,再乘j!(阶乘)。
C(i,m)*dp[n][i]*i!*C(m-i,m)*dp[n][j]*j!化简后是A(i+j,m)*dp[n][i]*dp[n][j];
最后就是取所有可能的i和j,把所有情况的答案加起来就是啦。
#include<cstdio>#include<cstring>typedef long long ll;ll dp[2005][2005],b[2005][2005];//注意数组开的是ll const ll mod=1000000007;int main(){dp[1][1]=1; for(ll i=2;i<=2000;i++){ for(ll j=1;j<=i;j++){ dp[i][j]=((j*dp[i-1][j])%mod+dp[i-1][j-1])%mod; } }b[1][1]=1;for(ll i=2;i<=2000;i++){ b[i][0]=1; for(ll j=1;j<=i;j++){ b[i][j]=(b[i][j-1]*(i-j+1))%mod;//求A(j,i),i中取j个 } }ll t;scanf("%lld",&t);while(t--){ll n,m;ll ans=0;scanf("%lld%lld",&n,&m);for(ll i=1;i<=m;i++){//姓中取i个字母 for(ll j=1;j+i<=m;j++){//名中取j个字母 ans=(ans+(b[m][i+j]*dp[n][i]%mod)*dp[n][j]%mod)%mod; } }printf("%lld\n",ans);}return 0;}
阅读全文
0 0
- 2017多校8-1011killer name
- Killer Names 2017 多校 8
- HDU-2017 多校训练赛8-1011-Killer Names
- HDU 2017 多校联合训练赛8 1011 6143 Killer Names 排列组合
- 2017多校八 1011题 hdu 6143 Killer Names 排列组合
- 2017 杭电多校赛第八场 1011题 Killer Names HDu 6143
- 多校8 HDU-6143 Killer Names 排列组合&斯特灵数
- Hdu6143 Killer Names(2017多校第8场)
- hdu6143 Killer Names 2017多校第八场1011 组合数学
- 2017多校训练八-1011(hdu 6143 Killer Names)
- hdu6143-多校8&三种方法-组合数|递推|容斥-Killer Names
- HDU 6143 Killer Names (容斥, 2017 Multi-Univ Training Contest 8)
- 2017-03-04 HDU1426 Sudoku Killer
- HDU 5328(2015多校4)-Problem Killer(水题)
- hdu 6143 Killer Names (2017多校第八场)
- OOM killer
- The Killer
- oom killer
- MySQL的字符格式
- oracle监听程序当前无法识别连接符中请求的服务
- Maven学习(二)使用命令创建maven项目
- Period||POJ1961
- CF 590D Top Secret Task【dp递推+滚动数组】【好题】
- 2017多校8-1011killer name
- c#创建带参数的线程
- Java条形码生成技术-Barcode4j
- HDU 6138 Fleet of the Eternal Throne (2017多校8
- JavaScript中的call方法
- PAT 1036 跟奥巴马一起编程
- 2017第八次多校联合hdu6140(阅读题)
- Docker化tomcat并且使用maven热部署
- mfs分布式文件存储(终)