zoj 3604 Tunnel Network(数字快速幂)
来源:互联网 发布:上海黑桃互动 知乎 编辑:程序博客网 时间:2024/06/17 01:29
转载请注明出处:http://blog.csdn.net/u012860063
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4707
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 withN-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 theS 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.
Input
There are multiple test cases. The first line of input contains an integer T (T ≤ 500) indicating the number of test cases. Then T test cases follow.
Each case contains one line containing two integer N (2 ≤ N ≤ 2000) andS (2 ≤S ≤ N), as described above.
Output
The number of possible networks now. Since the number might be very large, you should output the answer after modulo 1000000007.
Sample Input
43 24 25 3100 50
Sample Output
2815113366355
代码如下(申明此代码纯属巧过):
#include <iostream>#include <sstream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <map>#include <set>#include <bitset>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <climits>typedef long long LL;using namespace std ;#define mod 1000000007LL quickmod (LL a,LL b) {LL ans = 1;while(b) {if(b&1){ans = (ans * a)%mod;b--;}b >>= 1;a = (a * a)%mod;}return ans;}LL n, s;int main(){LL T;scanf("%lld",&T);while(T--){scanf("%lld %lld",&n,&s);if(n==s){puts("1");continue;}LL ans = quickmod(n,n - s - 1);ans = (ans * s)%mod;printf("%lld\n", ans);}return 0;}
- zoj 3604 Tunnel Network(数字快速幂)
- ZOJ 3604 Tunnel Network
- ZOJ 3604 Tunnel Network
- ZOJ 3604 Tunnel Network
- TOJ 4287 ZOJ 3604 Tunnel Network / prufer序列
- ZOJ 3604 Tunnel Network [Prüfer编码与Cayley公式] 【树】
- zoj 2853 Evolution(矩阵快速幂)
- ZOJ 3497 Mistwald(矩阵快速幂)
- ZOJ 3497 Mistwald(矩阵快速幂)
- ZOJ 3497-Mistwald(矩阵快速幂)
- 数字快速幂(模板)
- 矩阵快速幂ZOJ
- ZOJ 1914 Arctic Network(解题报告)
- zoj QS 1586 Network (prim算法)
- ZOJ 1586 QS Network (MST)
- 【ZOJ】1586 - QS Network(克鲁斯塔尔)
- ZOJ QS Network(最小生成树)
- TOJ 4287 Tunnel Network -- Prufer序列
- 第一周__算法概论思维导图
- ubuntu12.04 更新完源 出现 GPG error
- 计算机视觉领域的一些牛人博客,超有实力的研究机构等的网站链接
- 第二周作业
- HDU 4020 Ads Proposal(很巧妙的哈希)
- zoj 3604 Tunnel Network(数字快速幂)
- VMware Workstation 10 安装 Oracle Linux 6.4(Redhat6、CentOS6通用)
- 设计模式与iOS
- java--继承,抽象,接口
- LCD驱动分析
- 计算字符串的相似度
- ZOJ-1002
- distinct、order by、 group by实现原理
- Lync Server 查看和删除已经发布的中央管理存储位置