Codeforces 15E Triangles 【组合计数】
Codeforces 15E Triangles
Last summer Peter was at his granny’s in the country, when a wolf attacked sheep in the nearby forest. Now he fears to walk through the forest, to walk round the forest, even to get out of the house. He explains this not by the fear of the wolf, but by a strange, in his opinion, pattern of the forest that has n levels, where n is an even number.
In the local council you were given an area map, where the granny’s house is marked by point H, parts of dense forest are marked grey (see the picture to understand better).
After a long time at home Peter decided to yield to his granny’s persuasions and step out for a breath of fresh air. Being prudent, Peter plans the route beforehand. The route, that Peter considers the most suitable, has the following characteristics:
it starts and ends in the same place — the granny’s house;
the route goes along the forest paths only (these are the segments marked black in the picture);
the route has positive length (to step out for a breath of fresh air Peter has to cover some distance anyway);
the route cannot cross itself;
there shouldn’t be any part of dense forest within the part marked out by this route;
You should find the amount of such suitable oriented routes modulo 1000000009.
The example of the area map for n = 12 is given in the picture. Since the map has a regular structure, you can construct it for other n by analogy using the example.
Input
The input data contain the only even integer n (2 ≤ n ≤ 106).
Output
Output the only number — the amount of Peter’s routes modulo 1000000009.
Examples
input
2
output
10
input
4
output
74
先大大的%yyf大神的blog 大神blog
讲的贼详细
好吧
这题看起来挺麻烦的
但是我们发现首先方向是可以直接乘2乘掉的,其次两边的情况是可以平方掉的
然后我们只需要考虑一遍的情况了
然后我们找一下规律发现
对于每个
这样的东东,每一层(两行)倒着的三角的个数和在这一行折返的方案数是可以找到规律的
tipi=tipi−1∗2+3" role="presentation">tipi=tipi−1∗2+3tipi=tipi−1∗2+3
然后累乘一下就好啦
#include<bits/stdc++.h>
using namespace std;
#define yyf 1000000009
int main(){
long long ans=2,n,tip1=1,tip2=1;
cin>>n;n/=2;
if(n==1){cout<<10;return 0;}
n--;
while(n--){
ans=(ans+tip2*4)%yyf;
tip1=(tip1*2+3)%yyf;
tip2=(tip2*tip1)%yyf;
}
ans=(ans*ans%yyf*2+2)%yyf;
cout<<ans;
return 0;
}
Codeforces 15E Triangles 【组合计数】的更多相关文章
- Codeforces 15E Triangles - 组合数学
Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby fores ...
- CodeForces 57C Array 组合计数+逆元
题目链接: http://codeforces.com/problemset/problem/57/C 题意: 给你一个数n,表示有n个数的序列,每个数范围为[1,n],叫你求所有非降和非升序列的个数 ...
- bzoj 2281 [Sdoi2011]黑白棋(博弈+组合计数)
黑白棋(game) [问题描述] 小A和小B又想到了一个新的游戏. 这个游戏是在一个1*n的棋盘上进行的,棋盘上有k个棋子,一半是黑色,一半是白色. 最左边是白色棋子,最右边是黑色棋子,相邻的棋子颜色 ...
- BZOJ 4555: [Tjoi2016&Heoi2016]求和 [分治FFT 组合计数 | 多项式求逆]
4555: [Tjoi2016&Heoi2016]求和 题意:求\[ \sum_{i=0}^n \sum_{j=0}^i S(i,j)\cdot 2^j\cdot j! \\ S是第二类斯特林 ...
- BZOJ 4555: [Tjoi2016&Heoi2016]求和 [FFT 组合计数 容斥原理]
4555: [Tjoi2016&Heoi2016]求和 题意:求\[ \sum_{i=0}^n \sum_{j=0}^i S(i,j)\cdot 2^j\cdot j! \\ S是第二类斯特林 ...
- 【BZOJ5491】[HNOI2019]多边形(模拟,组合计数)
[HNOI2019]多边形(模拟,组合计数) 题面 洛谷 题解 突然特别想骂人,本来我考场现切了的,结果WA了几个点,刚刚拿代码一看有个地方忘记取模了. 首先发现终止态一定是所有点都向\(n\)连边( ...
- [总结]数论和组合计数类数学相关(定理&证明&板子)
0 写在前面 0.0 前言 由于我太菜了,导致一些东西一学就忘,特开此文来记录下最让我头痛的数学相关问题. 一些引用的文字都注释了原文链接,若侵犯了您的权益,敬请告知:若文章中出现错误,也烦请告知. ...
- 【BZOJ5323】[JXOI2018]游戏(组合计数,线性筛)
[BZOJ5323][JXOI2018]游戏(组合计数,线性筛) 题面 BZOJ 洛谷 题解 显然要考虑的位置只有那些在\([l,r]\)中不存在任意一个约数的数. 假设这样的数有\(x\)个,那么剩 ...
- 【BZOJ5305】[HAOI2018]苹果树(组合计数)
[BZOJ5305][HAOI2018]苹果树(组合计数) 题面 BZOJ 洛谷 题解 考虑对于每条边计算贡献.每条边的贡献是\(size*(n-size)\). 对于某个点\(u\),如果它有一棵大 ...
随机推荐
- 05_zookeeper_原生API使用1(更新)
1. java方式操作远端zookeeper集群概述 步骤:下载zookeeper压缩包并解压, 创建java工程,导入zookeeper相关jar包 (1)下载zookeeper压缩包 http:/ ...
- Sql类型
1.varchar和nvarchar的区别:varchar(n)长度为n个字节的可变长度且非Unicode的字符数据.n 必须是一个介于 1 和 8,000 之间的数值.存储大小为输入数据的字节的实际 ...
- Dubbo通过注解实现RPC调用
启动Dubbo服务有2个方式,1是通过xml配置,2是通过注解来实现,这点和Spring相似. 采用XML配置如下: <?xml version="1.0" encodin ...
- 黑客落网记:FBI如何抓捕Anonymous核心成员
腾讯科技讯 美国新闻网站Daily Dot近日撰文,通过他们掌握的资料和实地采访,还原了Anonymous核心成员被捕的经过. 以下为文章全文: 哈蒙德被捕前夜 2012年3月,一个周六的下午,天气异 ...
- 【BZOJ3144】切糕(网络流,最小割)
[BZOJ3144]切糕(网络流,最小割) 题面 BZOJ 题解 这样的类型很有趣 先不考虑相邻距离差不能超过\(D\)的限制 我们考虑答案,显然就是在每个位置选一个最小的高度割就行了 化成最小割的模 ...
- java 使用注释校验数据有效性
验证注解 验证的数据类型 说明 空检查 @Null 任意类型 验证注解的元素值是null @NotNull 任意类型 验证注解的元素不是null @NotBlank CharSequence子类型(C ...
- Java栈的两种实现
1. 基于数组 package Algorithm.learn; import java.util.Arrays; /** * Created by liujinhong on 2017/3/7. * ...
- HDU 4417 BIT or ST
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- asp.net服务器上无法发送邮件的问题
前几天为开发的网站做了个发送邮件的功能,但是部署到服务器上无法发送邮件,提示由于目标机器积极拒绝,无法连接.在网上找到了一个解决办法 如果安装了McAfee杀毒软件(按照“手工安装方法”安装),首先需 ...
- Ansible 小手册系列 十一(变量)
变量名约束 变量名称应为字母,数字和下划线. 变量应始终以字母开头. 变量名不应与python属性和方法名冲突. 变量使用 通过命令行传递变量(extra vars) ansible-playbook ...