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的更多相关文章
随机推荐
- Runloop深入理解
一.什么是Runloop?为什么需要Runloop? Runloop,顾名思义,即运行循环. 没有Runloop的情况下,一个线程执行完一个任务,就会退出并销毁.等到需要处理下一个任务时,再重新创建一 ...
- BLDC
BLDC working principle: https://www.bilibili.com/video/av31423350?from=search&seid=1569792618769 ...
- java 日期与时间类
1.Date类: https://www.cnblogs.com/huangminwen/p/5994927.html 2.DateFormat和SimpleDateFormat (simple简单 ...
- jmeter(十二)关联之正则表达式提取器
如果有这样的情况:一个完整的操作流程,需要先完成某个操作,获得某个值或数据信息,然后才能进行下一步的操作(也就是常说的关联/将上一个请求的响应结果作为下一个请求的参数): 在jmeter中,可以利用正 ...
- IIS 8的第一次请求不变慢如何配置
首先需要在Window中添加Application Initialization 在IIS中配置Application Pool 在IIS配置Web Site 配置完成,如果版本在7.5,可以下载:A ...
- highcharts中把X轴的名字竖着显示
Highcharts.chart('container', { chart: { type: 'column' }, title: { text: 'Auto rotation limit' }, s ...
- 在项目中,多个方法会调用相同的sql语句,怎么解决各个方法的不同sql查询,解决冲突。
公司的代码中sql语句,可能会被多个方法进行调用,但是有的方法会关联到别的表,这样的话,如果修改不当,那么同样调用该sql语句的方法,会出现报错. 最近做的公司的一个功能,就出现这样一个问题,虽然本功 ...
- CF1101G (Zero XOR Subset)-less 线性基
传送门 既然每一次选择出来的都是一个子段,不难想到前缀和计算(然而我没有想到--) 设异或前缀和为\(x_i\),假设我们选出来的子段为\([1,i_1],(i_1,i_2],...,(i_{k-1} ...
- WebApi 接口返回值不困惑:返回值类型详解。IHttpActionResult、void、HttpResponseMessage、自定义类型
首先声明,我还没有这么强大的功底,只是感觉博主写的很好,就做了一个复制,请别因为这个鄙视我,博主网址:http://www.cnblogs.com/landeanfen/p/5501487.html ...
- Python 学习 第四篇:动态类型模型
Python的变量不用声明,赋值之后就可以直接使用,类型是在运行过程中自动确定的,这就是动态类型模型.该模型把变量和对象设计成两个不同的实体,对象是存储数据的地方,对象的类型是由初始值自动决定的,而变 ...