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\),如果它有一棵大 ...
随机推荐
- Interleaving String,交叉字符串,动态规划
问题描述: Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Give ...
- ZooKeeper分布式锁简单实践
ZooKeeper分布式锁简单实践 在分布式解决方案中,Zookeeper是一个分布式协调工具.当多个JVM客户端,同时在ZooKeeper上创建相同的一个临时节点,因为临时节点路径是保证唯一,只要谁 ...
- 30分钟掌握Dart语言
在Dart中,一切都是对象,一切对象都是class的实例,哪怕是数字类型.方法甚至null都是对象,所有的对象都是继承自Object 虽然Dart是强类型语言,但变量类型是可选的因为Dart可以自动推 ...
- PHPCMSV9的CKEDITOR编辑器增加行距
lineheight插件,下载地址:http://files.cnblogs.com/ysfng/ckeditor-lineheight.zip 第一步,下载lineheight插件,并解压到\cke ...
- HTML5 history API,创造更好的浏览体验
HTML5 history API有什么用呢? 从Ajax翻页的问题说起 请想象你正在看一个视频下面的评论,在翻到十几页的时候,你发现一个写得稍长,但非常有趣的评论.正当你想要停下滚轮细看的时候,手残 ...
- Android程序的安装和打包
Android程序的安装和打包
- 1-16-1 LVM管理和ssm存储管理器使用&磁盘配额
大纲: 1-1- LVM逻辑卷的管理 1-2- SSM管理工具的使用 1-3- 磁盘配额技巧 ====================================== 问题描述: 当我们需要在一个 ...
- C# 设计模式巩固笔记 - 建造者模式
前言 写给自己-贵在坚持.建造者模式不复杂,但是想个形象的例子好难. 介绍-建造者模式 定义:将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示. 实现 建造者模式主要是应对复杂 ...
- hdu 5800 To My Girlfriend(背包变形)
To My Girlfriend Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- MySQL Block Nested-Loop Join(BNL)
5.5 版本之前,MySQL本身只支持一种表间关联方式,就是嵌套循环(Nested Loop).如果关联表的数据量很大,则join关联的执行时间会非常长.在5.5以后的版本中,MySQL通过引入BNL ...