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
Output
Sample Input
4
Sample Output
9
HINT
Source
#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
****************************************************************/