[Codeforces 15E] Triangle
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的更多相关文章
- Codeforces 15E Triangles 【组合计数】
Codeforces 15E Triangles Last summer Peter was at his granny's in the country, when a wolf attacked ...
- CodeForces 239A. Triangle
Link: http://codeforces.com/contest/407/problem/A 给定直角三角形的2个直角边a,b.求在直角坐标系中,是否存在对应的直角三角形,使得三个定点都在整点 ...
- Codeforces 15E Triangles - 组合数学
Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby fores ...
- codeforces C. Triangle
C. Triangle time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- codeforces 6A. Triangle
A. Triangle time limit per test 2 seconds memory limit per test 64 megabytes input standard input ou ...
- CodeForces - 18A Triangle(数学?)
传送门 题意: 给出三个点的坐标,初始,这三个点可以构成一个三角形. 如果初始坐标可以构成直角三角形,输出"RIGNT". 如果某个点的 x或y 坐标移动一个单位后可以组成直角三角 ...
- 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 ...
- Codeforces Beta Round #6 (Div. 2 Only) A. Triangle 水题
A. Triangle 题目连接: http://codeforces.com/contest/6/problem/A Description Johnny has a younger sister ...
- 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 ...
随机推荐
- poj 3422 洛谷P2045 K取方格数(方格取数加强版)
Description: 给出一个n*n的矩阵,每一格有一个非负整数Aij,(Aij <= 1000)现在从(1,1)出发,可以往右或者往下走,最后到达(n,n),每达到一格,把该格子的数取出来 ...
- 如何获取iframe DOM的值
在Web开发时,很多时候会遇到一个问题.我在一个页面嵌入了iframe,并且我想获得这个iframe页面某个元素的值.那么该如何实现这个需求呢? 先来看下演示: 效果演示 iframe1中文本框的值: ...
- LA2995 Image is everything
蓝书P12 #include <cstdio> #include <cstring> #include <cmath> #include <algorithm ...
- idea使用(一)
基本上正式开发的常用工具基本都集成了,而且基本都在你非常容易触到的位置.说说我比较常用的: 1.ant 你懂的 2.maven你也懂的 3.SVN相比之下,IDEA的SVN的提交提供了更多的选项和功能 ...
- Ubuntu 编译Webkit --gtk
转载自:http://www.linuxidc.com/Linux/2011-10/44809.htm webkit是一个浏览器内核,google的chrome就是基于它的,下面介绍一下如何在Ubun ...
- NodeJS概述
NodeJS中文API 一.概述 Node.js 是一种建立在Google Chrome’s v8 engine上的 non-blocking (非阻塞), event-driven (基于事件的) ...
- bzoj 5028: 小Z的加油店——带修改的区间gcd
Description 小Z经营一家加油店.小Z加油的方式非常奇怪.他有一排瓶子,每个瓶子有一个容量vi.每次别人来加油,他会让 别人选连续一段的瓶子.他可以用这些瓶子装汽油,但他只有三种操作: 1. ...
- asp单页面301跳转
<% Response.Status="301 Moved Permanently"Response.AddHeader "Location", &quo ...
- LeetCode 2 :Swap Nodes in Pairs
我的代码是这样的: class Solution { public: ListNode *swapPairs(ListNode *head) { ; ; ListNode *listA; ListNo ...
- 大型网站调试工具之一(php性能优化分析工具XDebug)
一.安装配置 1.下载PHP的XDebug扩展,网址:http://xdebug.org/ 2.在Linux下编译安装XDebug 引用 tar -xzf xdebug-2.0.0RC3.gzcd x ...