Codeforces 15E Triangles 【组合计数】

本文详细解析Codeforces15E题目“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=tipi12+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;
}

转载于:https://www.cnblogs.com/dream-maker-yk/p/9676323.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值