Lucky Coins Sequence
Lucky Coins Sequence |
| Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) |
| Total Submission(s): 35 Accepted Submission(s): 29 |
|
Problem Description
As we all know,every coin has two sides,with one side facing up and another side facing down.Now,We consider two coins's state is same if they both facing up or down.If we have N coins and put them in a line,all of us know that it will be 2^N different ways.We call a "N coins sequence" as a Lucky Coins Sequence only if there exists more than two continuous coins's state are same.How many different Lucky Coins Sequences exist?
|
|
Input
There will be sevaral test cases.For each test case,the first line is only a positive integer n,which means n coins put in a line.Also,n not exceed 10^9.
|
|
Output
You should output the ways of lucky coins sequences exist with n coins ,but the answer will be very large,so you just output the answer module 10007.
|
|
Sample Input
3 |
|
Sample Output
2 |
|
Source
2010 ACM-ICPC Multi-University Training Contest(9)——Host by HNU
|
|
Recommend
zhengfeng
|
/*
题意:定义一个硬币序列,如果超过三个相邻的硬币的正反相同,那么这个序列就是Lucky序列,给出序列
长度n,问有几种Lucky序列 初步思路:这种题型一般都是递推过来的,不管了先打表试一下
打表结果:(从3开始的)
2
6
16
38
86
188
402
846
1760
3630
7438
15164
30794
62342
125904
253782
510758
1026684
每项和前项的二倍差的数刚好是一个变形的斐波那契数列。
得到递推公式:G(n)=2*(G(n-1)+F(n-2));
#感悟:一边AC爽
*/
#include<bits/stdc++.h>
#define mod 10007
using namespace std;
/********************************矩阵模板**********************************/
class Matrix {
public:
int a[3][3]; void init(int x) {
memset(a,0,sizeof(a));
if(x==1){
a[0][0]=2;
a[0][1]=1;
a[0][2]=1;
}else{
a[0][0]=2;
a[1][0]=2;
a[1][1]=1;
a[1][2]=1;
a[2][1]=1;
}
} Matrix operator +(Matrix b) {
Matrix c;
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
c.a[i][j] = (a[i][j] + b.a[i][j]) % mod;
return c;
} Matrix operator +(int x) {
Matrix c = *this;
for (int i = 0; i < 3; i++)
c.a[i][i] += x;
return c;
} Matrix operator *(Matrix b)
{
Matrix p;
memset(p.a,0,sizeof p.a);
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
for (int k = 0; k < 3; k++)
p.a[i][j] = (p.a[i][j] + (a[i][k]*b.a[k][j])%mod) % mod;
return p;
} Matrix power_1(int t) {
Matrix ans,p = *this;
memset(ans.a,0,sizeof ans.a);
for(int i=0;i<3;i++) ans.a[i][i]=1;
while (t) {
if (t & 1)
ans=ans*p;
p = p*p;
t >>= 1;
}
return ans;
} Matrix power_2(Matrix a,Matrix b,int x){
while(x){
if(x&1){
b=a*b;
}
a=a*a;
x>>=1;
}
return b;
}
}unit,init;
/********************************矩阵模板**********************************/
int n;
int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d",&n)!=EOF){
if(n<3){
printf("0\n");
continue;
}
if(n==3){
printf("2\n");
continue;
}
unit.init(1);
init.init(0);
// for(int i=0;i<3;i++){
// for(int j=0;j<3;j++){
// cout<<unit.a[i][j]<<" ";
// }
// cout<<endl;
// }
init=init.power_1(n-3);
printf("%d\n",(unit*init).a[0][0]);
}
return 0;
}
Lucky Coins Sequence的更多相关文章
- poj3519 Lucky Coins Sequence矩阵快速幂
Lucky Coins Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 5985 Lucky Coins 数学
Lucky Coins 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5985 Description Bob has collected a lot ...
- HDU 5985/nowcoder 207D - Lucky Coins - [概率题]
题目链接:https://www.nowcoder.com/acm/contest/207/D 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5985 ...
- HDU5985 Lucky Coins 概率dp
题意:给你N种硬币,每种硬币有Si个,有Pi 概率朝上,每次抛所有硬币抛起,所有反面的拿掉,问每种硬币成为最后的lucky硬币的概率. 题解:都知道是概率dp,但是模拟赛时思路非常模糊,很纠结,dp[ ...
- HDU 5985 Lucky Coins(概率)
http://acm.split.hdu.edu.cn/showproblem.php?pid=5985 题意:有多种类型的硬币,每种类型的硬币都有一定的数量,现在每次抛硬币,除去朝下的硬币,知道最后 ...
- HDU.5985.Lucky Coins(概率DP)
题目链接 \(Description\) 有n(n<=10)种硬币,已知每种硬币的数量和它抛一次正面朝上的概率pi.进行如下过程:每次抛一次所有硬币,将正面朝下的硬币去掉.重复该过程直到只剩一种 ...
- 【概率论】hdu5985 Lucky Coins
kill(i,j)表示第i种硬币在第j轮或者之前就死光的概率,它等于(1-pi^j)^num(i) rev(i,j)表示第i种硬币在j轮后仍然存活的概率,它等于1-kill(i,j) 然后对每种硬币i ...
- 2016 ACM/ICPC亚洲区青岛站现场赛(部分题解)
摘要 本文主要列举并求解了2016 ACM/ICPC亚洲区青岛站现场赛的部分真题,着重介绍了各个题目的解题思路,结合详细的AC代码,意在熟悉青岛赛区的出题策略,以备战2018青岛站现场赛. HDU 5 ...
- 牛客国庆集训派对Day7 Solution
A Relic Discovery 水. #include <bits/stdc++.h> using namespace std; int t, n; int main() { s ...
随机推荐
- PuTsangTo-单撸游戏开发02 测试场景与单轴移动
且不说立项与设计阶段的工作量,一个完整的游戏在开发阶段设计的职责范围也是很广,还有个大问题就是PuTsangTo项目也是本人在边学边做,截止目前还是满满的无从下手的感觉,一方面是技能与经验不足,另一方 ...
- NOIP算法总结与复习
NOIP算法总结与复习 (看了看李总的蓝皮书,收获颇多,记下此文,以明志--) (一)数论 1.最大公约数,最小公倍数 2.筛法球素数 3.mod规律公式 4.排列组合数,错排 5.Catalan数 ...
- Java 中与(&)短路与(&&)以及 或(|)短路或(||)的关系
一.逻辑运算符的使用 1)逻辑运算符的连接的是布尔表达式,要与位运算符做区分. 2)使用方法: public class Test { public static void main(String[ ...
- Vi快捷操作 vim配置【shell文件格式从windows转换为linux】
vim配置 http://www.cnblogs.com/ma6174/archive/2011/12/10/2283393.html gg 首行 dd 删除当前行 :.,$d 删除全部内容 :se ...
- 如何使用windows版Docker并在IntelliJ IDEA使用Docker运行Spring Cloud项目
如何使用windows版Docker并在IntelliJ IDEA使用Docker运行Spring Cloud项目 #1:前提准备 1.1 首先请确认你的电脑是windows10专业版或企业版,只有这 ...
- spring 内部工作机制(二)
本章节讲Spring容器从加载配置文件到创建出一个完整Bean的作业流程及参与的角色. Spring 启动时读取应用程序提供的Bean配置信息,并在Spring容器中生成一份相应的Bean配置注册表, ...
- vs 或 Sql server2012连接Sql server时出现的问题:已成功与服务器建立连接,但在登陆过程中发生错误
以前连接是正常的,就这两天连不上了.(没有耐心的直接看末尾解决办法) 错误消息如下: 1.尝试读取或写入受保护的内存.这通常指示其他内存已损坏.(System.Data) 2.已成功与服务器建立连接, ...
- MVC中@RenderBody、@RenderSection、@RenderPage、@Html.RenderPartial、Html.RenderAction的作用和区别
1.@RenderBody() 作用和母版页中的服务器控件类似,当创建基于此布局页面的视图时,视图的内容会和布局页面合并,而新创建视图的内容会通过布局页面的@RenderBody()方法呈现在标签 ...
- JavaScriptOOP
1. OOP基础 1.1面向对象编程OOP 1.语言的分类: ① 面向机器:汇编语言 ② 面向过程:C语言 ③ 面向对象:C++ Java PHP 等 2.面向过程与 ...
- git 分支改名
给一个git分支改名的方法很简单 如果对于分支不是当前分支,可以使用下面代码: git branch -m 原名 新 如果是当前,那么可以使用加上新名字 git branch -m 原名 参见: ht ...