hdu 6143(精妙的递推)
来源:互联网 发布:马尔可夫链 转化矩阵 编辑:程序博客网 时间:2024/05/21 01:30
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。求可以取多少个不重复的名字。
分析:其实就是涂色问题了,dp[i][j]表示长度为i用了j种颜色的方案数。所以:dp[i][j]=(dp[i-1][j]*j+dp[i-1][j-1]*(m-j+1);
代码:
#include<bits/stdc++.h>using namespace std;typedef long long LL;const int maxn=2005;const LL mod=1e9+7;LL dp[maxn][maxn];//长度为i用了j种颜色LL poww(int n,int m){ LL ans=1,base=n; while(m>0) { if(m&1) ans=(ans*base)%mod; base=(base*base)%mod; m>>=1; } return ans%mod;}int main(){ int T; scanf("%d",&T); while(T--) { int n,m; scanf("%d%d",&n,&m); dp[1][1]=m; for(int i=2;i<=n;i++) { for(int j=1;j<=min(m,i);j++) { dp[i][j]=((dp[i-1][j]*j)%mod+(dp[i-1][j-1]*(m-j+1))%mod)%mod; } } LL ans=0; for(int i=1;i<=m-1;i++) { ans+=(dp[n][i]*poww(m-i,n))%mod;//左右两边方案数相乘即可。 ans%=mod; } printf("%lld\n",ans); } return 0;}
阅读全文
0 0
- hdu 6143(精妙的递推)
- hdu 2046(递推)
- HDU 5273(递推)
- hdu 5273(递推)
- hdu 2563(递推)
- hdu Coins (递推)
- hdu 2709(递推)
- HDU-2044(递推)
- HDU-2045(递推)
- HDU-2047(递推)
- hdu 2073 无限的路 (递推)
- HDU 2018 - 母牛的故事( 递推 )
- HDU 阿牛的EOF牛排(递推)
- HDU 2045--LELE的RPG难题(递推)
- HDU 2018 母牛的故事(递推)
- HDU 2018 母牛的故事(递推)
- HDU 1267 下沙的沙子有几粒?(递推)
- HDU 2018 母牛的故事(DP递推)
- 微信分享 errorCode 为-6
- poj 2441 Arrange the Bulls (状压dp)
- 《华为机试在线训练》之汽水瓶
- HDFS知识点总结
- hdu6154 CaoHaha's staff 找规律
- hdu 6143(精妙的递推)
- uC/OS-II系统学习笔记(5)—— uC/OS-II概述下篇
- 如何重写PictureBox的OnPaint方法绘制矩形,并实现拖动,鼠标悬停时提示拖拽方向
- Docker阿里加速器
- Java集合类
- Spring编程<二>
- validate 使用,存着
- hadoop之旅(五)
- 重构-代码的坏味道