HUD-5379
Mahjong tree
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 506 Accepted Submission(s): 161
Thought for a long time, finally he decides to use the mahjong to decorate the tree.
His mahjong is strange because all of the mahjong tiles had a distinct index.(Little sun has only n mahjong tiles, and the mahjong tiles indexed from 1 to n.)
He put the mahjong tiles on the vertexs of the tree.
As is known to all, little sun is an artist. So he want to decorate the tree as beautiful as possible.
His decoration rules are as follows:
(1)Place exact one mahjong tile on each vertex.
(2)The mahjong tiles' index must be continues which are placed on the son vertexs of a vertex.
(3)The mahjong tiles' index must be continues which are placed on the vertexs of any subtrees.
Now he want to know that he can obtain how many different beautiful mahjong tree using these rules, because of the answer can be very large, you need output the answer modulo 1e9 + 7.
For each test case, the first line contains an integers n. (1 <= n <= 100000)
And the next n - 1 lines, each line contains two integers ui and vi, which describes an edge of the tree, and vertex 1 is the root of the tree.
3
9
2 1
3 1
4 3
5 3
6 2
7 4
8 7
9 3
8
2 1
3 1
4 3
5 1
6 4
7 5
8 4
1
Case #1: 32
Case #2: 16
Case #3: 1
/**
题意:给一个树,现在要求一个树的叶子结点之间的数十连续的,并且一个树的所有的
子数节点的数也是连续的
做法:搜索
如果当前节点头n个节点,如果没有非叶子的节点那么它的可能是n!
否则 如果存在一个非叶子节点 那么就是2*(n-1)! 一段区间的开始和结束
如果存在两个非叶子节点 那么就是2*(n-2)!
如果非叶子节点大于2 那么该树没有解
**/
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <vector>
using namespace std;
#define maxn 100000 + 10
const int mod = 1e9 + ;
vector<int>G[maxn];
long long res = ;
int vis[maxn];
bool flag = true;
void dfs(int u)
{
vis[u] = ;
int tt = G[u].size();
int cet = ;
for(int i = ; i < tt; i++)
{
int v = G[u][i];
if(vis[v]) {
continue;
}
if(G[v].size() == && vis[v] == ) {
cet++;
}
else if(vis[v] == ) {
dfs(v);
}
}
if(u != ) {
tt--;
}
if(tt - cet > )
{
flag = false;
return;
}
if(tt - cet > )
{
res *= ;
res %= mod;
}
while(cet > )
{
res *= cet;
res %= mod;
cet--;
}
}
int main()
{
int T;
scanf("%d", &T);
int Case = ;
while(T--)
{
int n;
scanf("%d", &n);
int u, v;
memset(vis, , sizeof(vis));
for(int i = ; i <= n; i++)
{
G[i].clear();
}
for(int i = ; i < n - ; i++)
{
scanf("%d %d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
}
res = ;
flag = true;
dfs();
if(n == ) {
res = ;
}
else {
res *= ;
}
if(flag == false) {
printf("Case #%d: 0\n", Case++);
}
else {
printf("Case #%d: %lld\n", Case++, res % mod);
}
}
return ;
}
HUD-5379的更多相关文章
- 如何用Unity GUI制作HUD
若知其所以然,自然知其然. HUD是指平视显示器,就是套在脸上,和你的眼睛固定在一起,HUD的意思就是界面咯,一般我们说HUD特指把3D空间中的界面的某些信息(比如血条,伤害之类)的贴在界面上,对应3 ...
- xamarin UWP平台下 HUD 自定义弹窗
在我的上一篇博客中我写了一个在xamarin的UWP平台下的自定义弹窗控件.在上篇文章中介绍了一种弹窗的写法,但在实际应用中发现了该方法的不足: 1.当弹窗出现后,我们拖动整个窗口大小的时候,弹窗的窗 ...
- xamarin UWP设置HUD加载功能
使用xamarin开发的时候经常用到加载HUD功能,就是我们常见的一个加载中的动作,Android 下使用 AndHUD , iOS 下使用 BTProgressHUD, 这两个在在 NuGet 上都 ...
- OSG中的HUD
OSG中的HUD 所谓HUD节点,说白了就是无论三维场景中的内容怎么改变,它都能在屏幕上固定位置显示的节点. 实现要点: 关闭光照,不受场景光照影响,所有内容以同一亮度显示 关闭深度测试 调整渲染顺序 ...
- CREATE A ENERGY / HEALTH BAR HUD
Now then, let's get started. 1. Open the Play scene which you had created in the previous post. If y ...
- iOS之UI--指示器HUD的创建和设置
指示器的创建和设置 渐变动画 描述: 使用label就能制作指示器,原理:就是让label以动画的形式慢慢显示和消失 最好是半透明的 指示器有时候也被称为:HUD,遮盖,蒙版 思路步骤: 1.先在st ...
- NGUI:HUD Text(头顶伤害漂浮文字)
HUD Text 很早之前就有闻于NGUI中的HUD Text插件,今天得以尝试,看了会儿官方的文档,楞是没给看明白,官方的ReadMe.txt写的使用方法如下: 官网Usage 1. Attach ...
- iOS开发必备HUD(透明指示层)
iOS开发必备HUD(透明指示层) 字数421 阅读2123 评论1 喜欢51 1.MBProgressHUD GitHub地址:https://github.com/jdg/MBProgressHU ...
- UE4编程之C++创建一个FPS工程(二)角色网格、动画、HUD、子弹类
转自:http://blog.csdn.net/u011707076/article/details/44243103 紧接上回,本篇文章将和大家一同整理总结UE4关于角色网格.动画.子弹类和HUD的 ...
- HUD 2203 亲和串
HUD 2203 亲和串 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768K (Java/Others) [题目描述 - ...
随机推荐
- 洛谷 P1527 [国家集训队]矩阵乘法 解题报告
P1527 [国家集训队]矩阵乘法 题目描述 给你一个\(N*N\)的矩阵,不用算矩阵乘法,但是每次询问一个子矩形的第\(K\)小数. 输入输出格式 输入格式: 第一行两个数\(N,Q\),表示矩阵大 ...
- 阿里云学生机——Mysql配置---教小白入门篇
首先,我的学生机默认配置为:CentOS 7.2 64位 + Tomcat 8 + Jdk8 + MySQL5.7.16 扩展:Linux 如何查看 MySQL 版本号----使用命令 mysql - ...
- 51nod 1197 字符串的数量 V2(矩阵快速幂+数论?)
接上一篇,那个递推式显然可以用矩阵快速幂优化...自己随便YY了下就出来了,学了一下怎么用LaTeX画公式,LaTeX真是个好东西!嘿嘿嘿 如上图.(刚画错了一发...已更新 然后就可以过V2了 or ...
- Lua Go R HEXO Kotlin 简单介绍
Lua Lua使用C编写而成的脚本语言.同为脚本语言的Python拥有庞大的类库工具包,定位于独立开发,Lua极度精简化,没有提供太多功能包,必须与C.C++等语言混合使用,目的是为了快速并动态的嵌入 ...
- STL之一:字符串用法详解
转载于:http://blog.csdn.net/longshengguoji/article/details/8539471 字符串是程序设计中最复杂的变成内容之一.STL string类提供了强大 ...
- SDUT 3930 线段树
皮卡丘的梦想2 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 一天,一只住在 501 实验 ...
- 一图看懂深度学习框架对比----Caffe Torch Theano TensorFlow
Caffe Torch Theano TensorFlow Language C++, Python Lua Python Python Pretrained Yes ++ Yes ++ Yes ...
- [Coding Practice] Maximum number of zeros in NxN matrix
Question: Input is a NxN matrix which contains only 0′s and 1′s. The condition is no 1 will occur in ...
- 【HDU】3068 最长回文
[算法]manacher [题解][算法]字符串 #include<cstdio> #include<algorithm> #include<cstring> us ...
- Vuejs - 组件式开发
初识组件 组件(Component)绝对是 Vue 最强大的功能之一.它可以扩展HTML元素,封装可复用代码.从较高层面讲,可以理解组件为自定义的HTML元素,Vue 的编译器为它添加了特殊强大的功能 ...