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. springboot数据库操作及事物管理操作例子

    一.配置文件 pom.xml <dependency> <groupId>org.springframework.boot</groupId> <artifa ...

  2. Spring Boot的自动配置的原理

    Spring Boot在进行SpringApplication对象实例化时会加载META-INF/spring.factories文件,将该配置文件中的配置载入到Spring容器. 1.1.1.   ...

  3. 基于事件的 JavaScript 编程:异步与同

    JavaScript的优势之一是其如何处理异步代码.异步代码会被放入一个事件队列,等到所有其他代码执行后才进行,而不会阻塞线程.然而,对于初学者来说,书写异步代码可能会比较困难.而在这篇文章里,我将会 ...

  4. 迷宫实现递归版本C++

    迷宫实现递归版本C++ 问题描述: //////////////////////////////////////////////////////////////题目:迷宫求解问题. 大致思路: //1 ...

  5. node-glob 匹配通配符

    1.https://www.cnblogs.com/liulangmao/p/4552339.html 2.https://github.com/isaacs/node-glob 3.https:// ...

  6. http协议code码

    301 永久重定向 类似手机呼叫转移 302 临时重定向 类似手机呼叫转移 403 forbidden ngnix怎么解决? 含义:表示你在请求一个资源文件,但是nginx不允许你查看. 原因1:访问 ...

  7. linux中的redis缓存服务器

    Linux中的Redis缓存服务器 一.Redis基础部分: 1.redis介绍与安装比mysql快10倍以上 *****************redis适用场合**************** 1 ...

  8. 023——VUE中数据排序sort() / 数据反转 reverse() 的使用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. eureka -1 - 介绍

    eureka ,服务发现注册中心 eureka 包含server, client两部分. eureka server,服务发现组件,各个微服务启动的时候会向server注册自己的信息(ip,hostn ...

  10. LeetCode OJ:Nim Game(Nim游戏)

    You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...