Triangles
看了一天卡特兰数...我要自闭了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 种是这样,另外的是顺时针顺序地走
Solution:首先第 1 层是最特殊的,因为这里没有灰色的三角形,然后注意到灰色的部分把整个金字塔分成了左部和右部
路径现在可以分成三个部分
- 在第一层移动,这一共 10 种(见样例)
- 进入左部或右部后直接回到 H
- 进入左部(右部)后经过 E 点进入右部(左部)
对于第二种情况,在第一层的部分走法可以是(只有逆时针部分,实际上有 8 种)
对于第三种情况,在第一层(原来图中的两层现在算一层,也就是下面的 n 是题目中 n 的 12 )的部分走法有 2 种,左部到右部和右部到左部
现在要统计的就是在左部和右部内有多少种方案,因为左部右部对称,所以答案是一样的,我们来考虑左部
用 Sn 表示在有 n 层的金字塔中,走左部的方案数,因为走进左部后每一层都会遇到凹进去的部分,这部分只要枚举一下走了多远可以统计出第 n 层一共有
这么多的情况
因此
答案是
(没错我借鉴了老师的ppt
#include <cstdio> #include <iostream> #include <cstring> #include <string> #include <algorithm> 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; }
好难啊。。。。
舍管阿姨真烦....连作业都不让写.....什么时候才能回去啊....
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· DeepSeek 解答了困扰我五年的技术问题。时代确实变了!
· PPT革命!DeepSeek+Kimi=N小时工作5分钟完成?
· What?废柴, 还在本地部署DeepSeek吗?Are you kidding?
· DeepSeek企业级部署实战指南:从服务器选型到Dify私有化落地
· 程序员转型AI:行业分析