zjuoj 3604 Tunnel Network
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3604
Tunnel Network
Time Limit: 2 Seconds Memory Limit: 65536 KB
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 all N 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 excatly S 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.
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) and S (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
4
3 2
4 2
5 3
100 50
Sample Output
2
8
15
113366355
Author: WANG, Yelei
Contest: The 9th Zhejiang Provincial Collegiate Programming Contest
分析:
不过对于给定的n和s,可以对n-s个点先排列然后划分成s份,然后计算有x个点树有多少种。这样显然不好递推,也没法写公式。事实上对任意n个点构成的树对应一个长为n-2的Prufer序列,且这种关系是一一对应。所谓Prufer序列是每次拿掉编号最小的叶节点然后将它的父亲push,直到只剩下两个节点。因此可以假定有点0与s个城市分别相连,问题转化为这n+1个点构成的树的Prufer序列有多少种。注意到序列倒数第s个数必为1~s中的某一个且最后s-1个数必为根节点0,于是排列数为n^(n-s-1)*s。
prufer序列:http://www.cnblogs.com/jeff-wgc/p/4472528.html
AC代码:
#include <cstdio>
#define Mod 1000000007 int T, s, t;
long long n, r; inline int cal()
{
if(n == s) return ;
t = n-s-, r = s;
while(t > )
{
if(t&) r=(r*n)%Mod;
t >>=, n=(n*n)%Mod;
}
return r;
} int main()
{
scanf("%d", &T);
while(T --)
{
scanf("%d%d", &n, &s);
printf("%d\n", cal());
}
return ;
}
zjuoj 3604 Tunnel Network的更多相关文章
- ZOJ 3604 Tunnel Network(凯莱定理)
题目链接: E - Tunnel Network ZOJ - 3604 题目大意: 给定编号1-n的点,和给定编号1-S 的联通图,刚开始1号联通图只有 1个顶点,就是编号为1的顶点,2号联通图也只有 ...
- wpa_supplicant.conf
转自:http://w1.fi/gitweb/gitweb.cgi?p=hostap.git;a=blob_plain;f=wpa_supplicant/wpa_supplicant.conf ### ...
- Networking in too much detail
The players This document describes the architecture that results from a particular OpenStack config ...
- wpa_supplicant软件架构分析
wpa_supplicant软件架构分析 1. 启动命令 wpa supplicant 在启动时,启动命令可以带有很多参数,目前我们的启动命令如下: wpa_supplicant /system/bi ...
- D01 Elon Mulsk The future we're building — and boring
摘要:精选TED. 每个音频不超过2分钟,学英语和吸收伟大思想两不误 音频: https://n1audio.hjfile.cn/st/fb5ace6f-7b63-439d-954c-c4539c1f ...
- D02 TED Elon Mulsk The future we're building — and boring
摘要:精选TED. 每个音频不超过2分钟,学英语和吸收伟大思想两不误 音频: https://n1audio.hjfile.cn/st/de745862-d5f4-4ef4-9218-d79361ca ...
- 三:OVS+GRE之完整网络流程
知识点一:linux网桥提供安全组 知识点二:每新建一个网络,在网络节点都会新建一个namespace,只要为该网络建立子网,那么该namespace里就新增dhcp来为该子网分配ip,也可以为该网络 ...
- 2012-2014 三年浙江 acm 省赛 题目 分类
The 9th Zhejiang Provincial Collegiate Programming Contest A Taxi Fare 25.57% (166/649) (水 ...
- openstack-ansible Chapter 4. Deployment configuration
Initial environment configuration Copy the contents of the /opt/openstack-ansible/etc/openstack_depl ...
随机推荐
- vs2013单元测试第二部分
上次的随笔说还没弄懂,现在已经弄懂,就让我说说我的方法吧. 1.点击文件——>新建——>项目——>c#——>控制台应用程序,确定,之后如图所示 2.在一定位置写上要进行单元检测 ...
- bug:[NSKeyedUnarchiver initForReadingWithData:]: data is NULL
一,经历 1.问题出在给NSMutableDictionary类型的字典设置内容上. [_dictRateApp setObject:[NSNumber numberWithBool:NO] forK ...
- weblogic 11g 配置db2数据源
配置db2数据源可以直接在包里面配置,不需要专门在服务器上配置数据源. 在11g版本前要配置db2数据源是需要增加包,后续的版本处理了这个问题. 1. 将C:\Program Files\SQLLIB ...
- App所需申请资料
准备资料 企业五证 营业执照 税务登记证 组织机构代码证 银行开户许可证 法人身份证 新邮箱 申请一个新的邮箱地址,供申请以下材料使用 苹果证书申请 AppleID 申请邓氏编码需要有AppleID ...
- (转载)String.IsNullorEmpty()方法的使用
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ...
- SQL 中怎么查询一个数据库中一共有多少个表
用户表:select count(*) 总表数 from sysobjects where xtype='u' 总表数:select count(*) 总表数 from sysobject s whe ...
- 几种常用的JS类定义方法
几种常用的JS类定义方法 // 方法1 对象直接量var obj1 = { v1 : "", get_v1 : function() { return ...
- JQuery插件让图片旋转任意角度且代码极其简单
引入下方的jquery.rotate.js文件,然后通过$("选择器").rotate(角度);可以旋转任意角度, 例如$("#rotate-image").r ...
- java web(二) Tomcat数据源
一.数据源的产生 1.JDBC操作原理 (1) 加载数据库驱动程序(数据库驱动程序可通过classpath配置): Class.forName(); (2)通过DriverManager类取得数据库连 ...
- win7 、win10连接l2tpvpn
win7: 修改vpn连接选项: win10: 参考连接: http://service.njaf.gov.cn/26970/26971/201510/t20151024_3621861.html ...