Bubble Cup 8 finals H. Bots (575H)
题意:
简单来说就是生成一棵树,要求根到每个叶子节点上的路径颜色排列不同,
且每条根到叶子的路径恰有n条蓝边和n条红边。
求生成的树的节点个数。
1<=n<=10^6
题解:
简单计数。
显然,前n层的边的颜色是任意的,所以第i层就是2^i个点。
对于后n层,可以直接由上一层转移。
因为已经知道上一层合法的个数,那么如果现在每个点扩展两条边,
那么上一层的状态中,某种颜色的个数已经达到n的情况就有一条边不可扩展,
所以要减去2*C(i-1,n)。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 #include <cstdio>
#include <cstring>
typedef long long lint;
const int N = , MO = ;
int n,n2,ps,pr[N],fc[N],iv[N],ans;
int powmod(int a,int b)
{
int s = ;
for(;b;b>>=)
{
if(b&) s = (lint)s*a%MO;
a = (lint)a*a%MO;
}
return s;
}
void init(int n)
{
int i,j;
for(fc[]=,i=;i<=n;i++) fc[i] = (lint)fc[i-]*i%MO;
for(iv[n]=powmod(fc[n],MO-),i=n;i>=;i--) iv[i-] = (lint)iv[i]*i%MO;
}
inline int getc(int a,int b)
{
return (lint)fc[a]*iv[a-b]%MO*iv[b]%MO;
}
int main()
{
scanf("%d",&n); n2 = n<<;
init(n*);
int i,j,t=,c=;
ans = ;
for(i=;i<=n;i++) t = ((lint)t<<)%MO, ans = ((lint)ans+t)%MO;
for(i=n+;i<=n2;i++)
t = (((lint)t<<)-((lint)getc(i-,n)<<))%MO, ans = ((lint)ans+t)%MO;
printf("%d\n",(ans+MO)%MO);
return ;
}
Bubble Cup 8 finals H. Bots (575H)的更多相关文章
- Bubble Cup 12 - Finals Online Mirror, unrated, Div. 1
Bubble Cup 12 - Finals Online Mirror, unrated, Div. 1 C. Jumping Transformers 我会状压 DP! 用 \(dp[x][y][ ...
- Bubble Cup 11 - Finals [Online Mirror, Div. 1]题解 【待补】
Bubble Cup 11 - Finals [Online Mirror, Div. 1] 一场很好玩的题啊! I. Palindrome Pairs 枚举哪种字符出现奇数次. G. AI robo ...
- Codeforces Bubble Cup 8 - Finals [Online Mirror]H. Bots 数学
H. Bots Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/H Desc ...
- Bubble Cup 8 finals G. Run for beer (575G)
题意: 给定一个带权无向图,每条边的代价为边权/当前速度,每次到达一个新节点,速度都会除以10. 求0号点到n-1号点的最小代价,如果多解输出点数最少的解,输出代价.路径点数.路径经过的点. 1< ...
- Bubble Cup 8 finals B. Bribes (575B)
题意: 给定一棵n个点和有向边构成的树,其中一些边是合法边,一些边是非法边, 经过非法边需要1的费用,并且经过之后费用翻倍. 给定一个长为m的序列,问从点1开始按顺序移动到序列中对应点的总费用. 1& ...
- Codeforces Bubble Cup 8 - Finals [Online Mirror] F. Bulbo DP
F. Bulbo Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/F Des ...
- Bubble Cup X - Finals [Online Mirror] B. Neural Network country 矩阵快速幂加速转移
B. Neural Network country time limit per test 2 seconds memory limit per test 256 megabytes Due to t ...
- codeforce1046 Bubble Cup 11 - Finals 题解
比赛的时候开G开了3h结果rose说一句那唯一一个AC的是羊的心态就崩了.. 这套题感觉质量挺好然后就back了下 A: AI robots 有三个限制条件:相互能够看见和智商的差.使用主席树,可以维 ...
- Bubble Cup 12 - Finals [Online Mirror, unrated, Div. 1] E. Product Tuples
题意略,题解生成函数练习题,1+(q-ai)x卷积即可,线段树优化(类似分治思想) //#pragma GCC optimize(2) //#pragma GCC optimize(3) //#pra ...
随机推荐
- mariadb数据库忘记密码如何找回
1.systemctl stop mariadb ==>停止mariadb数据库 2.mysqld_safe --skip-grant-tables & ==>进入单机模式 3.m ...
- WPF 自定义列表筛选 自定义TreeView模板 自定义ListBox模板
有很多项目,都有数据筛选的操作.下面提供一个案例,给大家做参考. 左侧是数据源,搜索框加TreeView控件,右侧是ListBox控件.在左侧数据列点击添加数据,然后点击确定,得到所筛选的数据. 下面 ...
- centos7的网络设置
必备知识:linux下对文件的编辑操作 首先给出的是vi的基础 后面会有详细的远程连接Centos的方法 vi的基本概念 基本上vi可分为三种操作状态,分别是命令模式(Command mode).插 ...
- SQL 中的 AND OR
AND 和 OR 运算符用于基于一个以上的条件对记录进行过滤. AND 和 OR 运算符 AND 和 OR 可在 WHERE 子语句中把两个或多个条件结合起来. 如果第一个条件和第二个条件都成立,则 ...
- pitch yaw roll是什么
虚拟现实 三维空间的右手笛卡尔坐标如图1所示. 图1 在航空中,pitch, yaw, roll如图2所示. pitch是围绕X轴旋转,也叫做俯仰角,如图3所示. yaw是围绕Y轴旋转,也叫偏航角,如 ...
- iOS 解决LaunchScreen中图片加载黑屏问题
iOS 解决LaunchScreen中图片加载黑屏问题 原文: http://blog.csdn.net/chengkaizone/article/details/50478045 iOS 解决Lau ...
- [LeetCode] Minimum Moves to Equal Array Elements II 最少移动次数使数组元素相等之二
Given a non-empty integer array, find the minimum number of moves required to make all array element ...
- [LeetCode] Minimum Moves to Equal Array Elements 最少移动次数使数组元素相等
Given a non-empty integer array of size n, find the minimum number of moves required to make all arr ...
- [LeetCode] Integer Replacement 整数替换
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If ...
- [LeetCode] Reverse Nodes in k-Group 每k个一组翻转链表
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If ...