[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 ...
随机推荐
- git使用笔记(九)操作原理
By francis_hao Nov 27,2016 参考[1]的一张图已经把git的基本原理描述的很清楚了,如下: 下面以实例演示其过程,需要用到两个命令cat-file和ls-fil ...
- shell脚本应用
解析乱的日志文件到临时文件中,然后用awk 1004 cd /usr/local 1005 ll 1006 cd pttmsg/ 1007 ll 1008 cd msgbin-2/ ...
- HDU3338:Kakuro Extension(最大流)
Kakuro Extension Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- java常用的时间格式
年月日时分秒毫秒:yyyyMMddHHmmssSSS 毫秒用SSS表示.
- Spring学习-- SpEL表达式
Spring 表达式语言(简称SpEL):是一个支持运行时查询和操作对象图的强大的表达式语言. 语法类似于 EL:SpEL 使用 #{...} 作为定界符 , 所有在大括号中的字符都将被认为是 SpE ...
- jquery.cookie.js 的使用指南
转自:http://www.cnblogs.com/yjzhu/p/4359420.html 介绍: jquery.cookie.js 是一款轻量级的 cookie 插件,可以读取,写入和删除 coo ...
- TensorFlow_曲线拟合
# coding:utf-8 import tensorflow as tf import numpy as np import matplotlib.pyplot as plt import os ...
- AtCoder Regular Contest 092 C D E F
C - 2D Plane 2N Points 题意 二维平面上有\(N\)个红点,\(N\)个蓝点,一个红点和一个蓝点能配成一对当且仅当\(x_r<x_b\)且\(y_r<y_b\). 问 ...
- Linux进程的Uninterruptible sleep(D)状态【转】
转自:http://c20031776.blog.163.com/blog/static/68471625201121522824111/ 运行在KVM虚拟机里的一些进程突然出了问题,这些出了问题的进 ...
- Guava Cache相关
官方:http://ifeve.com/google-guava-cachesexplained/ 理解:https://segmentfault.com/a/1190000007300118 项目中 ...