CF 166E Tetrahedron
2 seconds
256 megabytes
standard input
standard output
You are given a tetrahedron. Let's mark its vertices with letters A, B, C and D correspondingly.
An ant is standing in the vertex D of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.
You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex D to itself in exactly n steps. In other words, you are asked to find out the number of different cyclic paths with the length of n from vertex D to itself. As the number can be quite large, you should print it modulo 1000000007 (109 + 7).
The first line contains the only integer n (1 ≤ n ≤ 107) — the required length of the cyclic path.
Print the only integer — the required number of ways modulo 1000000007 (109 + 7).
2
3
4
21
The required paths in the first sample are:
- D - A - D
- D - B - D
- D - C - D
【题意】
给一个四面体,从顶点D沿棱走n步回到D,问方案数。
【分析】
引自__http://www.cnblogs.com/zyf0163/p/4318036.html
【代码】
#include<cstdio>
using namespace std;
const int N=1e7+5;
const long long mod=1e9+7;
int n;long long f[N];
int main(){
f[1]=0;f[2]=3;
scanf("%d",&n);
for(int i=3;i<=n;i++){
f[i]=2*f[i-1]+3*f[i-2];
f[i]%=mod;
}
printf("%I64d\n",f[n]);
return 0;
}
CF 166E Tetrahedron的更多相关文章
- CodeForces 166E -Tetrahedron解题报告
这是本人写的第一次博客,学了半年的基础C语言,初学算法,若有错误还请指正. 题目链接:http://codeforces.com/contest/166/problem/E E. Tetrahedro ...
- Codeforces 矩阵题 题单
Matrix CF 166E Tetrahedron dp方程设为 f[i] 最后在 D点,g[i] 表示最后不在D点.最后 g[] 可以通过矩阵加速数列求得,数据可以强化,复杂度 \(O(logn) ...
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- CF memsql Start[c]UP 2.0 A
CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...
- CF memsql Start[c]UP 2.0 B
CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...
随机推荐
- UFLDL教程练习(exercise)答案(2)
主成分分析与白化,这部分很简单,当然,其实是用Matlab比较简单,要是自己写SVD分解算法,足够研究好几个月的了.下面是我自己实现的练习答案,不保证完全正确,不过结果和网站上面给出的基本一致. 1. ...
- SharePoint PowerShell使用Export-SPWeb和Import-SPWeb指令来导出和导入网站
导出网站,例如: Export-SPWeb -Identity http://win2012sp2013:1000/Hopewell_Portal/ -Path "C:\KenmuTemp\ ...
- 在Unity3d中调用外部程序及批处理文件
如果调用外部普通应用程序, 比如notepad.exe 这样调用 static public bool ExecuteProgram(string exeFilename, string workDi ...
- False 'Sharing Violation' Xcopy error message
今天想要将QC的新工具自动拷贝到p4 用户机器上使用,为了避免每次通知大家升级啊!!! 于是,我在程序里调用了bat文件,执行拷贝操作,想在默默的情况下替换更新新版本工具,结果我测试发现没能成功更新版 ...
- QT QGraphicsProxyWidget对象可选择或移动的一些tricks
我在QT图形视图框架中使用QGraphicsProxyWidget嵌入widget,但是无法使其和其它的QGraphicsItem一样可以选择或移动,使用如下语句无效: C++ Code 1234 ...
- 【笔试面试】神马搜索C++程序猿电话面试
面试时间:2015.07.15 预约时间:2015.07.14.电话面试前一天,会电话咨询你方面电话面试的时间. 面试环节: 无自我介绍(这是我面试这么多家公司碰到的第一次),直接面试内容. 问题1: ...
- Android Studio 视图解析
AS一共同拥有三种视图.我们来分别分析每一种视图的作用. 一.Project视图.(白色字体的文件夹/文件可不关注) 图片中的链接 Gralde介绍:http://stormzhang.com/dev ...
- Go之对象拷贝
这里interface{}就相当于c#,java中的object, boy := util.Boy{util.Person{"Eric", 19, "boy"} ...
- 【代码审计】LaySNS_v2.2.0 前台XSS跨站脚本漏洞
0x00 环境准备 LaySNS官网:http://www.laysns.com/ 网站源码版本:LaySNS_v2.2.0 程序源码下载:https://pan.lanzou.com/i0l38 ...
- CentOS7--Firewalld防火墙
Firewalld服务是红帽RHEL7系统中默认的防火墙管理工具,特点是拥有运行时配置与永久配置选项且能够支持动态更新以及"zone"的区域功能概念,使用图形化工具firewall ...