DNA poj2440

Description
A kind of virus has attacked the X planet, and many lives are infected. After weeks of study, The CHO (Creature Healthy Organization) of X planet finally finds out that this kind of virus has two kind of very simple DNA, and can be represented by 101 and 111. Unfortunately, the lives on the planet also have DNA formed by 0s and 1s. If a creature’s DNA contains the virus’ DNA, it will be affected; otherwise it will not. Given an integer L, it is clear that there will be 2 ^ L different lives, of which the length of DNA is L. Your job is to find out in the 2 ^ L lives how many won’t be affected?
Input
The input contains several test cases. For each test case it contains a positive integer L (1 <= L <= 10 ^ 8). The end of input is indicated by end-of-file.
Output
For each test case, output K mod 2005, here K is the number of lives that will not be affected.
Sample Input
4
Sample Output
9

(1)题意:一种病毒入侵了,病毒有两种DNA 111和101,人有L位的基因,也是由0和1组成。如果人的基因中有与病毒相同的串,则会被影响,问,给一个L,有多少中可能的基因组合不会受到影响。结果对2005取模。
(2)解法1:L的取值为10^8次方,显然数据很大,但结果对2005取模,说明可能有混环节。对前几项进行手工运算找规律。
1 —> 2 1*2 2 —> 4 2*2
3 —> 6 2*3 4 —> 9 3*3
5 —> 15 3*5 6 —> 25 5*5
7 —> 40 5*8 8 —> 64 8*8
9 —> 104 8*13 10 —> 169 13*13
可以看出为斐波拉契数列:1 2 3 5 8 13 21 。然后找循环节。
解法2:找规律:f[n]=f[n-1]+f[n-3]+f[n-4];然后在找循环节。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
    int n,i;
    int f[10000]={1,2};
    for(i=2;i<10000;i++)
    {
        f[i]=(f[i-1]+f[i-2])%2005;
        if(f[i]==2&&f[i-1]==1) break;
    }
   // printf("%d",i-1);
    while(scanf("%d",&n)==1)
    {
        int p=(f[(n/2+n%2)%(i-1)]*f[n/2%(i-1)])%2005;
        printf("%d\n",p);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值