Brief Introduction:

求从N出发,回到N且不包含任何黑色三角的路径数

Algorithm:
假设从N点到第二层中间的节点M的路径数为k,易知总路径数为(k*k+1)*2

而从第第四层开始,每两行之间的形状是具有规律的,我们称之为一个“凹槽”。

每个“凹槽”的方案数是具有规律的:2n-2到2n间的方案数F(n)=2^n-3(不考虑从最外层跳到次外层)

所以到恰好到第2n层的总方案数S(n)=4*F(3)*F(4)......*F(n),res=6+S(3)+S(4)....+S(n)

由于一共只能从最外层跳一次到次外层,所以将4乘出来

Code:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MOD=1e9+; int main()
{
int n;cin >> n; if(n==) return cout << ,; ll a=,cur=,res=;
for(int i=;i<=n/;i++)
a=a*%MOD,cur=(cur*(a-+MOD))%MOD,res=(res+cur)%MOD;
cout << *(res*res+)%MOD;
return ;
}

Review:

1、找到位置转移的一些规律(只能跳跃一次),将转换的方式另外乘出来即可

2、发现递进性的规律,大胆推公式,注意好初始化与特解即可

[Codeforces 15E] Triangle的更多相关文章

  1. Codeforces 15E Triangles 【组合计数】

    Codeforces 15E Triangles Last summer Peter was at his granny's in the country, when a wolf attacked ...

  2. CodeForces 239A. Triangle

    Link:  http://codeforces.com/contest/407/problem/A 给定直角三角形的2个直角边a,b.求在直角坐标系中,是否存在对应的直角三角形,使得三个定点都在整点 ...

  3. Codeforces 15E Triangles - 组合数学

    Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby fores ...

  4. codeforces C. Triangle

    C. Triangle time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  5. codeforces 6A. Triangle

    A. Triangle time limit per test 2 seconds memory limit per test 64 megabytes input standard input ou ...

  6. CodeForces - 18A Triangle(数学?)

    传送门 题意: 给出三个点的坐标,初始,这三个点可以构成一个三角形. 如果初始坐标可以构成直角三角形,输出"RIGNT". 如果某个点的 x或y 坐标移动一个单位后可以组成直角三角 ...

  7. Codeforces Round #396 (Div. 2) B. Mahmoud and a Triangle 贪心

    B. Mahmoud and a Triangle 题目连接: http://codeforces.com/contest/766/problem/B Description Mahmoud has ...

  8. Codeforces Beta Round #6 (Div. 2 Only) A. Triangle 水题

    A. Triangle 题目连接: http://codeforces.com/contest/6/problem/A Description Johnny has a younger sister ...

  9. Codeforces Round #396 (Div. 2) A - Mahmoud and Longest Uncommon Subsequence B - Mahmoud and a Triangle

    地址:http://codeforces.com/contest/766/problem/A A题: A. Mahmoud and Longest Uncommon Subsequence time ...

随机推荐

  1. zigbee ---- profile 和 cluster

    在zigbee规范中,引入了profile, cluster的概念.具体说来,假设规范一个profile(可以理解成一套规定),这个profile用来规范智能家居领域的相关产品都要满足那些要求,那么h ...

  2. mysql__视图

    视图 1.什么是视图 视图是一种虚拟存在的表,对于使用视图的用户来说基本上是透明的.视图并不是在数据库中实际存在的,行和列数据来自定义视图的查询中使用的表,并且是在使用视图时动态生成的 视图相对于普通 ...

  3. CSS选择器及CSS3新增选择器

    转自:http://www.cnblogs.com/libingql/p/4375354.html 1. CSS1定义的选择器 选择器 类型 说明 E 类型选择器 选择指定类型的元素 E#id ID选 ...

  4. 我自己的python开发环境

    1.开发工具 eclipse 所有的版本下载: https://www.eclipse.org/downloads/index-packages.php , 我下载的是比较低的版本:https://w ...

  5. poj1379 Run Away

    传送门:http://poj.org/problem?id=1379 [题解] 题目大意:求(0,0)->(X,Y)内的一个点,使得这个点到给定的n个点的最小距离最大. 模拟退火 一开始可以先把 ...

  6. 我在一个前端项目中用js整理的一些通用方法,其中使用到的思想,主要就是约定了。

    把名称和后台来的json数据约定起来,可以达到的效果就是可以将东西统一化,减少差异,提升模块等的通用性,此后就可以实现具体不同模块内容可以自动或拷贝赋值的方式 2016.7.18 refactor s ...

  7. TASK_KILLABLE:Linux 中的新进程状态【转】

    转自:https://www.ibm.com/developerworks/cn/linux/l-task-killable/index.html 新的睡眠状态允许 TASK_UNINTERRUPTI ...

  8. Kuangbin 带你飞 最小生成树题解

    整套题都没什么难度. POJ 1251 Jungle Roads #include <map> #include <set> #include <list> #in ...

  9. 让button居中显示的的标签

    <center> <input type="button" class="buttoncls" style="width:80px& ...

  10. 6.flume实战(三)※

    需求:将A服务器上的日志实时采集到B服务器上面去 大致原理: 技术选型: exec source + memory channel + avro sink avro source + memory c ...