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 【组合计数】的更多相关文章

  1. Codeforces 15E Triangles - 组合数学

    Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby fores ...

  2. CodeForces 57C Array 组合计数+逆元

    题目链接: http://codeforces.com/problemset/problem/57/C 题意: 给你一个数n,表示有n个数的序列,每个数范围为[1,n],叫你求所有非降和非升序列的个数 ...

  3. bzoj 2281 [Sdoi2011]黑白棋(博弈+组合计数)

    黑白棋(game) [问题描述] 小A和小B又想到了一个新的游戏. 这个游戏是在一个1*n的棋盘上进行的,棋盘上有k个棋子,一半是黑色,一半是白色. 最左边是白色棋子,最右边是黑色棋子,相邻的棋子颜色 ...

  4. 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是第二类斯特林 ...

  5. 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是第二类斯特林 ...

  6. 【BZOJ5491】[HNOI2019]多边形(模拟,组合计数)

    [HNOI2019]多边形(模拟,组合计数) 题面 洛谷 题解 突然特别想骂人,本来我考场现切了的,结果WA了几个点,刚刚拿代码一看有个地方忘记取模了. 首先发现终止态一定是所有点都向\(n\)连边( ...

  7. [总结]数论和组合计数类数学相关(定理&证明&板子)

    0 写在前面 0.0 前言 由于我太菜了,导致一些东西一学就忘,特开此文来记录下最让我头痛的数学相关问题. 一些引用的文字都注释了原文链接,若侵犯了您的权益,敬请告知:若文章中出现错误,也烦请告知. ...

  8. 【BZOJ5323】[JXOI2018]游戏(组合计数,线性筛)

    [BZOJ5323][JXOI2018]游戏(组合计数,线性筛) 题面 BZOJ 洛谷 题解 显然要考虑的位置只有那些在\([l,r]\)中不存在任意一个约数的数. 假设这样的数有\(x\)个,那么剩 ...

  9. 【BZOJ5305】[HAOI2018]苹果树(组合计数)

    [BZOJ5305][HAOI2018]苹果树(组合计数) 题面 BZOJ 洛谷 题解 考虑对于每条边计算贡献.每条边的贡献是\(size*(n-size)\). 对于某个点\(u\),如果它有一棵大 ...

随机推荐

  1. 关于推荐库位 java前端与SQL语句后面的结合

    ----------------------------------------------------------------------------------- select a1.id,a1. ...

  2. css中pt、px、em、ex、in等这类长度单位详细说明

    在CSS样式表中,我们经常会看到pt, px,em,ex,in等这类长度单位.它们各是什么意思,有什么区别呢? 在CSS样式表中,长度单位分两种: 相对长度单位,如px, em等 绝对长度单位,如pt ...

  3. spring mvc: log4j插件 log日志的输出

    准备: log插件:log4j <!-- log日志插件 --> <!-- https://mvnrepository.com/artifact/log4j/log4j --> ...

  4. Java循环结构 - for, while 及 do...while

    Java循环结构 - for, while 及 do...while 顺序结构的程序语句只能被执行一次.如果您想要同样的操作执行多次,,就需要使用循环结构. Java中有三种主要的循环结构: whil ...

  5. Linux命令详解-touch

    linux的touch命令不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件. 1.命令格式: touch [选项]... 文件... 2.命令参数: -a 或- ...

  6. 各种数据库对应的jar包、驱动类名和URL格式

    1.1.       各种数据库对应的jar包 具体如下: 数据库类型 对应的Jar文件 Oracle 8i classes12.zip 或 ojdbc14.jar Sybase jconn2.jar ...

  7. javascript打开新窗体

    open -- 打开(弹出)一个新的窗体 open,中文"打开"的意思 引用网址:http://www.dreamdu.com/javascript/window.open Jav ...

  8. LeetCode OJ:Longest Substring Without Repeating Characters(最长无重复字符子串)

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  9. Spring写配置文件时不提示怎么办?

    想要编写xml文件时代码提示,其实只要配置了相应的xsd文件即可,xsd文件也就是xml文件的一个约束.就是决定了你xml文件中可以写哪些东西. xsd文件是xml文件的元数据文件. 以bean标签为 ...

  10. 12.18 分布式系统下的session

    广义的session: 会话控制,可以理解成为一种保存key-value的机制 从key的方面来看:sessionId和token sessionId: 服务端请求客户端的时候,服务端通过setcoo ...