F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Just A String

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1172    Accepted Submission(s): 324


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 \le n, m \le 2000)$.
 

Output
For each case, if the expected number is $E$, a single integer denotes $E \cdot m^n \text{ mod } 1000000007$.
 

Sample Input
3 2 2 3 2 10 3
 

Sample Output
10 40 1908021
 

Author
zimpha@zju
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-25 21:55:47, Gzip enabled