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

题目大意

  首先,请仔细看图,找出图中的规律。

  给定这个图的大小$n$,问有多少条有向路径满足:

  • 路径长度为正
  • 路径是沿着图中的边走的
  • 路径不能自交
  • 路径从H点开始,在H点结束
  • 路径不能将黑色的格子圈住

  答案模$10^{9}+9$。不是1e9 + 7。表示因为模数打错一发wa

   通过手动画图,可以发现,路径主要有2种


  • 这样的有向路径总共只有2条
  • 这样可以说是先在一侧乱窜,然后到点P,然后再到另一侧,最后在边上回到点H。

  由于图是对称的,统计的是有向路径,所以只需要通过计算在一侧,点H到点P的合法的无向路径的数量然后再进行简单的运算就能够算出答案。

  通过观察,可以发现,一旦从$l_{1}$上离开,就在到P点前不可能再回到$l_{1}$上。同时它也不可能继续向下走。

  所以考虑从$l_{1}$上的某一点,向右或者向右下走一步然后到达点P 的方案数。

  离开$l_{1}$后,就会沿大致向上的方向走,那么考虑在某个位置走到它的右上的方案数。

  这个稍微分类讨论一下

  1. 如果在这种地方,如果可以向右上走1步,那么方案数为1,否则为0。

  2. 如果跑到了这里,设下凸的个数为$n$,它的方案数为$g_{n}$。(注意,以下讨论的方案数是指在保证路径合法的情况下)那么考虑点A到点C的方案数,显然为2。
    然后考虑点C到点B的方案数和点D到点B的方案数,显然它们是1,至于点C到点D呢,根据定义可得它是$g_{n - 1}$。
    然后想想,点A到点B的路径有哪几种?

    $A\rightarrow B,A\rightarrow C\rightarrow B, A\rightarrow C \rightarrow D \rightarrow B$

    于是不难根据加法原理得到

    $g_{n} = 2g_{n - 1} + 3$

  然而有什么用呢?考虑刚离开$l_{1}$后到达的第一个点,那么它到点P的方案数就可以通过乘法原理计算。

  紧接着就可以计算出在离开$l_{1}$上每个点后到达点P的方案数。然后把它们加起来就能够得到总的方案数,

  假如成功算出了这样的总方案数为$s$,那么如何根据它来求答案呢?

  容易根据加法和乘法原理得到:

$ans = 2s^{2} + 2$

  说的很长,其实代码很短

Code

 /**
* Codeforces
* Problem#15E
* Accepted
* Time: 60ms
* Memory: 2024k
*/
#include <bits/stdc++.h>
using namespace std; const int M = 1e9 + ; int n; inline void init() {
scanf("%d", &n);
} int sum = ;
inline void solve() {
for (int i = , last = -, P = ; i <= n; i++) {
if (i & ) {
last = ( * last + ) % M;
P = (P * 1ll * last) % M;
}
sum = (sum + P) % M;
}
sum = (sum << ) % M;
sum = (sum * 1ll * sum) % M;
sum = ((sum + ) << ) % M;
printf("%d", sum);
} int main() {
init();
solve();
return ;
}

Codeforces 15E Triangles - 组合数学的更多相关文章

  1. Codeforces 15E Triangles 【组合计数】

    Codeforces 15E Triangles Last summer Peter was at his granny's in the country, when a wolf attacked ...

  2. Colorful Bricks CodeForces - 1081C ( 组合数学 或 DP )

    On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in t ...

  3. Codeforces 528E Triangles 3000 - 计算几何

    题目传送门 传送点I 传送点II 传送点III 题目大意 给定$n$的平面上的直线,保证没有三条直线共点,两条直线平行.问随机选出3条直线交成的三角形面积的期望. 显然$S=\frac{1}{2}ah ...

  4. Mysterious Crime CodeForces - 1043D (思维+组合数学)

    Acingel is a small town. There was only one doctor here — Miss Ada. She was very friendly and nobody ...

  5. codeforces 630H (组合数学)

    H - Benches Time Limit:500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit S ...

  6. [Codeforces 15E] Triangle

    Brief Introduction: 求从N出发,回到N且不包含任何黑色三角的路径数 Algorithm:假设从N点到第二层中间的节点M的路径数为k,易知总路径数为(k*k+1)*2 而从第第四层开 ...

  7. Educational Codeforces Round 32 Almost Identity Permutations CodeForces - 888D (组合数学)

    A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in thi ...

  8. Codeforces 990C (模拟+组合数学)

    题面: 传送门 分析: 此题O(n2l)" role="presentation" style="position: relative;">O( ...

  9. Codeforces 1093D(染色+组合数学)

    题面 传送门 题目大意:给出一个无向图,每个节点可以填1,2,3三个数中的一个 问有多少种填数方案,使两个相邻节点的数之和为奇数 分析 如果图中有奇环,一定无解 我们对图黑白染色,由于图可能不联通,记 ...

随机推荐

  1. python list成员函数extend与append的区别

    extend 原文解释,是以list中元素形式加入到列表中 extend list by appending elements from the iterable append(obj) 是将整个ob ...

  2. 关于调用数据库函数executeUpdate抛出异常

    2018.06.11写一个web程序的时候发现了一个问题,解决了好几天都没解决,并且也找不到问题所在.偶然百度找到了根源所在,希望可以帮到大家. 1 在调用这个函数的时候一直抛异常.刚开始我还以为是代 ...

  3. Linux的文件最大连接数

    [最大连接数]Linux的文件最大连接数   查看当前操作系统连接数设置 ulimit -a ==================================== 修改服务器最大连接数 vim / ...

  4. Unity之fragment shader中如何获得视口空间中的坐标

    2种方法: 1. 使用 VPOS 或 WPOS语义,如: Shader "Test/ScreenPos1" { SubShader { Pass { CGPROGRAM #prag ...

  5. linux小倒腾

    1.vim安装,sudo apt-get install vim-gtk,于是vim就安装好了.当然在我电脑上还出现了gvim,简单的vim配置(etc/vim/vimrc): "我的设置 ...

  6. Java集合-----List详解

    List中的元素是有序排列的而且可重复 1.LinkedList LinkedList是非线程安全的,底层是基于双向链表实现的       LinkedList常用方法:     toArray()  ...

  7. GGTalk即时通讯系统(支持广域网)终于有移动端了!(技术原理、实现、源码)

    首先要感谢大家一直以来对于GGTalk即时通讯系统的关注和支持!GGTalk即时通讯系统的不断完善与大家的支持分不开! 从2013年最初的GG1.0开放源码以来,到后来陆续增加了网盘功能.远程协助功能 ...

  8. samba共享目录无法访问的一般解决方案,非用户登录和读写权限问题

    配smb,被第四点坑了很久,特此转载. 由于这5点都是比较普通的情况,不涉及用户登录和读写权限问题 1)关闭防火墙: #sevice iptables stop 2)修改 /etc/samba/smb ...

  9. linux下postgresql的连接数配置

    1.查询当前连接数: select count(*) from pg_stat_activity; 2.查询最大连接数 show max_connections; 3.修改最大连接数 SHOW con ...

  10. HDU 2511 汉诺塔X

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2511 1,2,...,n表示n个盘子.数字大盘子就大.n个盘子放在第1根柱子上.大盘不能放在小盘上.在 ...