TOJ 4287 ZOJ 3604 Tunnel Network / prufer序列

Tunnel Network

时间限制(普通/Java):1000MS/3000MS     运行内存限制:65536KByte
 

描述

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;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值