HDU 6143 Killer Names (Rong Chi) __ Combination Mathematics

Source: Internet
Author: User
Description

Galen Marek, codenamed Starkiller, was a male Human The apprentice of the "Lord Sith Darth." A powerful Force-user who lived during the era of the Galactic Empire, Marek originated from the Wookiee home planet of Ka Shyyyk 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 is killed in battle by Darth Vader. Though only a child, Marek possessed a exceptionally strong connection to the Force this Dark lord of the Sith To exploit.

When Marek died in 2 BBY, shortly on the formation of the Alliance, Vader endeavored to recreate his disciple by Utiliz ing 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 it s Subjects-was initially imperfect and many clones were too-unstable to take ' s place as the Marek Lord ' s new Dark Ce. After months of failure, one particular clone impressed Vader enough-for-him to hope-this version might become the FI RST success. But as with the others, he inherited Marek's power and skills in the cost of receiving his emotions as, 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. 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 a becomes. A clone of Starkiller would be given a two-word name, a-name and a-name. Both the "name of the" and "the" last name have exactly n characters, while each character was chosen from a 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 the name is given, a clone would become unstable and would try to fight against his own master. A name is safe if and only if no character appears in both the name.

Since no two clones can share a name Darth Vader would like to know the maximum number of clones it able to create.

Input

The ' 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 10^9+7

Sample Input

2
3 2
2 3

Sample Output

2 
18

the

M-m colors need to be two length n N of the lattice staining, and the two paragraphs can not appear the same color, ask how many cases in total.

train of Thought

Enumeration the number of colors to allocate for these two paragraphs is I,j i,j, in the first paragraph there is a total (mi) \binom{m}{i} selection scheme, in the second paragraph there is a total (M−ij) \binom{m-i}{j} selection scheme.

And within each segment, we set F (n,x) f (n,x) to be the number of schemes with x x color (equal to x x) for the lattices of length n N.

Then according to the principle F (n,x) =xn− (x1) (x−1) n+ (x2) (x−2) n− (x3) (x−3) n+ ... F (n,x) =x^n-\binom{x}{1} (X-1) ^n+\binom{x}{2} (X-2) ^n-\binom{x}{3} (x-3) ^n+ ...

The final result is the sum of all (MI) f (n,i) x (M−ij) f (n,j) \binom{m}{i}f (n,i) x\binom{m-i}{j}f (n,j).

Supplemental 2017.08.18

A combinatorial explanation for the second class of Stirling s (p,k) s (p,k) is to divide P-p objects into k

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.