POJ 2440 DNA

本题地址:>here<

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

Source

POJ Monthly,Static

题解

我不得不承认这是道神奇的题目…
当我默默算出递推公式f(n)=f(n-1)+f(n-3)+f(n-4)后就蒙了

甚么鬼?

f(n)=f(n-1)+f(n-3)+f(n-4)

敢情这是高精度?
貌似不对…

一万年后,机智的我发现这应该有循环出现的情况(因为K要mod 2005)
于是乎

int f[1010]={1,2,4,6,9,15};
int test() {
    for(int i=5;i<=1000;i++) {
        f[i]=(f[i-1]+f[i-3]+f[i-4])%2005;
        if(f[i]==6&&f[i-1]==4&&f[i-2]==2&&f[i-3]==1)
            return i-3;
    }
}

我们高兴地发现循环节是200
再于是乎

#include<cstdio>
using namespace std;
int f[210]={1,2,4,6};
void F() {
    for(int i=4;i<200;i++)
        f[i]=(f[i-1]+f[i-3]+f[i-4])%2005;
}

int solve(int n) {
    n%=200;
    return f[n];
}

int n;
int main() {
    F();
    while(~scanf("%d",&n))
        printf("%d\n",solve(n));
    return 0;
}

over.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值