POJ 2440 DNA

来源:互联网 发布:吃月饼猜9字网络流行语 编辑:程序博客网 时间:2024/06/07 13:46

本题地址:>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.

0 0
原创粉丝点击