[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 ...
随机推荐
- BZOJ day2
十六题...(好难啊) 1051105910881191119214321876195119682242243824562463276128184720
- Collection与Map的对比
Map:HashMap.HashTable 如何在它们之间选择 一.Array , Arrays Java所有“存储及随机访问一连串对象”的做法,array是最有效率的一种. 1. 效率高, ...
- ERROR: Found lingering reference file hdfs
Found lingering reference异常 ERROR: Found lingering reference file hdfs://jiujiang1:9000/hbase/month_ ...
- 对Office文档进行授权
Microsoft.Office.Interop.Word.ApplicationClass app = new Microsoft.Office.Interop.Word.ApplicationCl ...
- 开发中常遇到的Python陷阱和注意点
最近使用Python的过程中遇到了一些坑,例如用datetime.datetime.now()这个可变对象作为函数的默认参数,模块循环依赖等等. 在此记录一下,方便以后查询和补充. 避免可变对象作为默 ...
- NodeJS概述
NodeJS中文API 一.概述 Node.js 是一种建立在Google Chrome’s v8 engine上的 non-blocking (非阻塞), event-driven (基于事件的) ...
- mongoDB的简单使用
1.客户端连接: ./mongo 2.数据库 一个mongodb中可以建立多个数据库. MongoDB的默认数据库为"db",该数据库存储在data目录中. MongoDB的单个实 ...
- python面向对象进阶(上)
一 .isinstance(obj,cls)和issubclass(sub,super) (1)isinstance(obj,cls)检查对象obj是否是类 cls 的对象,返回True和Flase ...
- How to learn wxPython
目录 How to learn wxPython Learn Python Choose a good editor Install wxPython Read the wxPython tutori ...
- UVALIVE 3486 Cells
通过入栈出栈顺序判断祖先关系 这里UVALIVE还 #include <map> #include <set> #include <list> #include & ...