Tunnel Network
描述
Country Far-Far-Away is a big country with N cities. But it is now under a civil war. The rebel uses the ancient tunnel network which connects allN cities with N-1 inter-city tunnels for transportation. The government army want to destroy these tunnels one by one. After several months fighting, some tunnels have been destoryed. According to the intel, the tunnel network have excatlyS connected components now. And what government army further knows is that city 1, 2, ... ,S belong to each of the S connected components. Since the government have little knowledge about the remaining tunnels, they ask you to calculate the number of possible networks of remaining tunnels.
输入
There are multiple test cases. The first line of input contains an integerT (T ≤ 500) indicating the number of test cases. Then T test cases follow.
Each case contains one line containing two integerN (2 ≤ N ≤ 2000) and S (2 ≤ S ≤ N), as described above.
输出
The number of possible networks now. Since the number might be very large, you should output the answer after modulo 1000000007.
样例输入
4
3 2
4 2
5 3
100 50
样例输出
2
8
15
113366355
http://www.cnblogs.com/luotinghao/p/3418619.html
#include <cstdio>
#include <iostream>
using namespace std;
const int mod = 1000000007;
int main()
{
int t,n,s,i;
scanf("%d", &t);
while(t--)
{
scanf("%d %d", &n, &s);
if(n == s)
{
puts("1");
continue;
}
__int64 ans = s;
for(i = 1; i <= n - s - 1; i++)
{
ans = (ans * n) % mod;
}
printf("%I64d\n", ans);
}
return 0;
}