博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Triangles
阅读量:6268 次
发布时间:2019-06-22

本文共 2731 字,大约阅读时间需要 9 分钟。

看了一天卡特兰数...我要自闭了QAQ

(如果不写一篇明天就会全部忘记QuQ

(要不感觉对不起看了一天别人的题解qwqqqq

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 n n levels, where n n 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 H 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 n=12 n=12 is given in the picture. Since the map has a regular structure, you can construct it for other n n n by analogy using the example.

Input

The input data contain the only even integer n n n ( 2<=n<=106 2<=n<=10^{6} 2<=n<=106 ).

Output

Output the only number — the amount of Peter's routes modulo 1000000009.

n=2 时,一共有 10 种方案,其中 5 种是这样,另外的是顺时针顺序地走

5E-triangles

Solution:首先第 1 层是最特殊的,因为这里没有灰色的三角形,然后注意到灰色的部分把整个金字塔分成了左部和右部

5E-triangles-level1

路径现在可以分成三个部分

  • 在第一层移动,这一共 10 种(见样例)
  • 进入左部或右部后直接回到 H
  • 进入左部(右部)后经过 E 点进入右部(左部)

对于第二种情况,在第一层的部分走法可以是(只有逆时针部分,实际上有 8 种)

对于第三种情况,在第一层(原来图中的两层现在算一层,也就是下面的 n 是题目中 n 的 12 )的部分走法有 2 种,左部到右部和右部到左部

现在要统计的就是在左部和右部内有多少种方案,因为左部右部对称,所以答案是一样的,我们来考虑左部

Sn 表示在有 n 层的金字塔中,走左部的方案数,因为走进左部后每一层都会遇到凹进去的部分,这部分只要枚举一下走了多远可以统计出第 n 层一共有

这么多的情况 

因此

答案是

(没错我借鉴了老师的ppt

#include 
#include
#include
#include
#include
const long long mod = 1000000009;using namespace std;int main(){ int n; scanf("%d", &n); long long pw = 2, g = 4, s = 0; while(n -= 2) { pw = (pw << 1) % mod; g = g * (pw - 3) % mod; s = (s + g) % mod; } int ans = (2 * s * s + 8 * s + 10) % mod; if(ans < 0) ans += mod; printf("%d\n", ans); return 0;}

好难啊。。。。

舍管阿姨真烦....连作业都不让写.....什么时候才能回去啊....

转载于:https://www.cnblogs.com/Grigory/p/10360121.html

你可能感兴趣的文章
JPopupMenu的使用以及JPopupMenu中子组件的事件处理
查看>>
从反汇编的角度看引用和指针的区别
查看>>
拓马长枪定乾坤
查看>>
UIProgressView的详细使用
查看>>
Silverlight实用窍门系列:70.Silverlight的视觉状态组VisualStateGroup
查看>>
照片筛选与上传功能
查看>>
Hello ZED
查看>>
常见web攻击方式
查看>>
hdu 4472
查看>>
oracle存储过程中is和as区别
查看>>
windows 2003 群集
查看>>
几个gcc的扩展功能
查看>>
Spark一个简单案例
查看>>
关于结构体占用空间大小总结(#pragma pack的使用)
查看>>
通过浏览器查看nginx服务器状态配置方法
查看>>
shell简介
查看>>
android 使用WebView 支持播放优酷视频,土豆视频
查看>>
怎么用secureCRT连接Linux
查看>>
C# 使用WinRar命令压缩和解压缩
查看>>
linux学习笔记一----------文件相关操作
查看>>