【POJ 2440】 Dna

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? 


对于一个长度为N的字符串,每个位置上仅可为0或者1.现在要求字符串中不能出现101或者111.问当确定N的值时,

有多少种合法的字符串,请将结果Mod 2005

Input

The input contains several test cases. For each test case it contains a positive integer L (1 <= L <= 10 ^ 6). 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

HINT

Source

设a[i]是到第i个的所有合法个数
因为不能出现101和111
所以只要最后一位是0就行即a[i-1]
如果最后一位是1
001
011
101
111
4种情况
101 和 111 不合法
001合法即a[i-3]
011 还需要考虑之前一位是否为1
如果是1,那么1011也不合法
所以必须是0011即 a[i-4]

所以a[i]=a[i-1]+a[i-3]+a[i-4]

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<iostream>
using namespace std;
int max1(int a, int b) {
    return a > b ? a : b;
}
int a[1000010];
int main() {
    //  freopen("in.txt", "r", stdin);
    //  freopen("out.txt", "w", stdout);
    int n;
    a[1] = 2;
    a[2] = 4;
    a[3] = 6;
    a[4] = 9;
    a[5] = 15;
    for (int i = 6; i <= 1000000; i++)
        a[i] = (a[i - 4] + a[i - 3] + a[i - 1]) % 2005;
    while (scanf("%d", &n) != EOF) {
        printf("%d\n", a[n]);
    }
    return 0;
}
 
/**************************************************************
    Problem: 1205
    User: xrq
    Language: C++
    Result: Accepted
    Time:20 ms
    Memory:5440 kb
****************************************************************/



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值