2015 Multi-University Training Contest 6 hdu 5362 Just A String
Just A String
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 643 Accepted Submission(s): 182
Problem Description
soda has a random string of length n which is generated by the following algorithm: each of n characters of the string is equiprobably chosen from the alphabet of size m.
For a string s, if we can reorder the letters in string s so as to get a palindrome, then we call s a good string.
soda wants to know the expected number of good substrings in the random string.
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line contains two integers $n and m (1 \leq n,m \leq 2000)$.
Output
For each case, if the expected number is E, a single integer denotes$ E\dot mn mod 1000000007$.
Sample Input
3
2 2
3 2
10 3
Sample Output
10
40
1908021
Author
zimpha@zju
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int maxn = ;
const int mod = ;
long long dp[maxn][maxn],PM[maxn];
int main() {
PM[] = dp[][] = ;
int kase,n,m;
scanf("%d",&kase);
while(kase--) {
scanf("%d%d",&n,&m);
dp[][] = m;
for(int i = ; i <= n; ++i) PM[i] = PM[i-]*m%mod;
for(int i = ; i <= n; ++i) {
for(int j = , k = min(i,m); j <= k; ++j) {
dp[i][j] = ;
if(j) dp[i][j] += dp[i-][j-]*(m - j + );
if(j + <= min(i - ,k)) dp[i][j] += dp[i-][j+]*(j + );
dp[i][j] %= mod;
}
}
long long ret = ;
for(int i = ; i <= n; ++i)
ret += dp[i][i&]*(n - i + )%mod*PM[n-i]%mod;
printf("%I64d\n",ret%mod);
}
return ;
}
2015 Multi-University Training Contest 6 hdu 5362 Just A String的更多相关文章
- 2015 Multi-University Training Contest 8 hdu 5390 tree
tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...
- 2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!
Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: ...
- 2015 Multi-University Training Contest 8 hdu 5385 The path
The path Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: 5 ...
- 2015 Multi-University Training Contest 3 hdu 5324 Boring Class
Boring Class Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- 2015 Multi-University Training Contest 3 hdu 5317 RGCDQ
RGCDQ Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- 2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple
CRB and Apple Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- 2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries
CRB and Queries Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- 2015 Multi-University Training Contest 6 hdu 5357 Easy Sequence
Easy Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 2015 Multi-University Training Contest 7 hdu 5378 Leader in Tree Land
Leader in Tree Land Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
随机推荐
- ACM-并查集之小希的迷宫——hdu1272
***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...
- URAL 1826. Minefield(数学 递归)
题目链接:http://acm.timus.ru/problem.aspx? space=1&num=1826 1826. Minefield Time limit: 0.5 second M ...
- Linux命令(一)——简单命令
一.简单命令 1.pwd命令 显示当前工作的全路径名. 2.date命令 显示系统当前的日期和时间. 3.who命令 显示当前已登录到系统的所有用户名,及其终端名和登录到系统的时间. 4.cal命令 ...
- 2016.04.06,英语,《Vocabulary Builder》Unit 10
put, from the Latin verb putare, meaning 'to think, consider, or believe'. reputation: [ˌrepju'teɪʃn ...
- SQL SERVER 读书笔记:非聚集索引
对于有聚集索引的表,数据存储在聚集索引的叶子节点,而非聚集索引则存储 索引键值 和 聚集索引键值.对于非聚集索引,如果查找的字段没有包含在索引键值,则还要根据聚集索引键值来查找详细数据,此谓 Book ...
- 使用Scanner获取键盘输入 (转)
原文地址:https://www.cnblogs.com/SzBlog/p/5404335.html 后面有改动 使用Scanner类可以很方便地便获取用户的键盘输入,Scanner是一个基于正则表达 ...
- 修复wordpress插件编辑器漏洞
具体方法,将下面的代码添加到您的配置文件 wp-config.php中: define( 'DISALLOW_FILE_EDIT', true ); 以此关闭插件编辑器功能,一切就这么简单,漏洞也就不 ...
- 5) 十分钟学会android--ActionBar知识串烧
建立ActionBar Action bar 最基本的形式,就是为 Activity 显示标题,并且在标题左边显示一个 app icon.即使在这样简单的形式下,action bar对于所有的 act ...
- hdu 3729 最大匹配
此题是我AC的HDU的201道题目.泪流满面啊! 字典序最大(最小)真是个烦人的东西. 学生i与其对应的分数区间的每个点连一条边.字典序最大,编号最大的学生开始匹配. HK无法AC啊,试了很久.我不会 ...
- 杭电2602 Bone Collector 【01背包】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 解题思路:给出一个容量为V的包,以及n个物品,每一个物品的耗费的费用记作c[i](即该物品的体积 ...