codeforces166E
Tetrahedron
You are given a tetrahedron. Let's mark its vertices with letters A, B, C and Dcorrespondingly.
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).
Input
The first line contains the only integer n (1 ≤ n ≤ 107) — the required length of the cyclic path.
Output
Print the only integer — the required number of ways modulo 1000000007 (109 + 7).
Examples
2
3
4
21
Note
The required paths in the first sample are:
- D - A - D
- D - B - D
- D - C - D
sol:直接dp丝毫不慌,dp[i][0/1/2/3]表示第i步,当前位于节点j的方案数
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n;
int a[N],A[N],Len[N];
int main()
{
int i,j,ans=;
R(n);
if(n<=) {Wl(n); return ;}
for(i=;i<=n;i++)
{
R(a[i]);
}
*A=;
for(i=;i<=n;i++)
{
if(a[i]>)
{
A[++*A]=a[i];
Len[*A]=;
}
else
{
A[++*A]=;
for(;i<=n&&a[i]==;i++) Len[*A]++;
i--;
}
}
for(i=;i<=n;i++) ans=max(ans,Len[i]);
if(*A==) ans=n;
if(*A==)
{
if(A[]==) ans=max(Len[],Len[]+);
else ans=Len[];
}
for(i=;i<=(*A)-;i++)
{
int tmp;
if(A[i]==)
{
tmp=Len[i+]+;
}
else if(A[i+]==)
{
if(Len[i+]==) tmp=Len[i+]+;
else
{
tmp=+Len[i+];
for(j=i+;j<=*A;j++)
{
if(A[j]==A[j-]+A[j-]) tmp+=Len[j];
else break;
}
ans=max(ans,tmp);
continue;
}
}
else tmp=Len[i]+Len[i+];
for(j=i+;j<=*A;j++)
{
if(A[j]==A[j-]+A[j-]) tmp+=Len[j];
else break;
}
ans=max(ans,tmp);
}
Wl(ans);
return ;
}
/*
input
10
1 2 3 5 8 13 21 34 55 89
output
10 input
5
1 1 1 1 1
output
2 input
10
1 1 0 0 0 0 0 0 0 1
output
7
*/
codeforces166E的更多相关文章
随机推荐
- 开放的dae模型
从网上看到了这段代码,就Copy过来了. 其实面对dae这种开放的模型格式,我们可以做很多事情,就像通常的XML文件一样. //------------------------------------ ...
- MiniProfiler工具介绍(监控EF生成的SQL语句)--EF,迷你监控器,哈哈哈
十年河东,十年河西,莫欺少年穷... 今天是抄袭的别人的博客,不过我感觉蛮好,挺有用,特别是老板让你优化EF项目SQL耗时的情况下,你可以采用这种方式来优化你的LINQ. 时间很宝贵,废话还是不多说, ...
- sklearn学习笔记之简单线性回归
简单线性回归 线性回归是数据挖掘中的基础算法之一,从某种意义上来说,在学习函数的时候已经开始接触线性回归了,只不过那时候并没有涉及到误差项.线性回归的思想其实就是解一组方程,得到回归函数,不过在出现误 ...
- OLED小记
1.点阵组成OLED,OLED中有一个GRAM区域,区域中的值直接刷新到屏幕上,对应关系是1bit对应一个像素点: 2.要点亮一个像素点,只需要将GRAM中的对应bit位写1即可.GRAM中是分页来管 ...
- python 常见矩阵运算
python 的 numpy 库提供矩阵运算的功能,因此我们在需要矩阵运算的时候,需要导入 numpy 的包. 1.numpy 的导入和使用 from numpy import *;#导入numpy的 ...
- [UWP 自定义控件]了解模板化控件(8):ItemsControl
1. 模仿ItemsControl 顾名思义,ItemsControl是展示一组数据的控件,它是UWP UI系统中最重要的控件之一,和展示单一数据的ContentControl构成了UWP UI的绝大 ...
- 【nodejs】让nodejs像后端mvc框架(asp.net mvc)一样处理请求--目录(8/8 完结)
为什么要做这个 在使用nodejs开发过程中,总是发现需要做很多重复性的体力劳动,且因为自身是服务端程序员出身,感觉有一些服务端好的东西其实可以在nodejs上得到应用并能提高一些开发工作效率. 本系 ...
- 运维中的日志切割操作梳理(Logrotate/python/shell脚本实现)
对于Linux系统安全来说,日志文件是极其重要的工具.不知为何,我发现很多运维同学的服务器上都运行着一些诸如每天切分Nginx日志之类的CRON脚本,大家似乎遗忘了Logrotate,争相发明自己的轮 ...
- Linux内核分析作业八
进程的切换和系统的一般执行过程 贾瑗 原创作品转载请注明出处 <Linux内核分析>MOOC课程 http://mooc.study.163.com/course/USTC-1000029 ...
- 安装tesserocr错误(未解决)
在win10下使用pip install tesserocr安装时,始终报错,未解决问题 解压tesserocr-2.2.2.tar.gz该文件夹后,查看setup.py文件,发现似乎model只能再 ...