POJ 2440 DNA

Source: Internet
Author: User

Links: http://poj.org/problem?id=2440

Dna
Time limit:1000ms Memory limit:65536ktotal submissions:3498 accepted:1375
Description
A kind of virus has attacked the X planet, and many lives is infected. After weeks of study, the CHO (Creature Healthy Organization) of X Planet finally finds out that this kind of virus have TW O kind of very simple DNA, and can is represented by 101 and 111. Unfortunately, the lives on the planet also has DNA formed by 0s and 1s. If a creature ' s DNA contains the virus ' DNA, it'll be affected; Otherwise it would not. Given an integer l, it's clear that there'll be 2 ^ L different lives, of which the length of DNA is L. Your job is-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, the output K mod 2005, here K was the number of lives that would not be affected.

Sample Input4

Sample Output9

Source

POJ monthly,static

The main idea-a virus that invades a planet, which has two kinds of DNA, 111 and 101, which has an L-bit gene and is made up of 0 and 1. If a biological gene contains the same substring as the virus, it will be affected. Q: Given an L, how many possible combinations of genes will not be affected, resulting in 2005 modulo.

Thought--l value is larger than the largest, the maximum is 10^8, but the result to 2005 modulo, the explanation must exist the Circulation section, and must have the recursion relation. Note: F (0) =1,f (1) =2,f (2) =4,f (3) =6,f (4) =9,f (5) =15,f (6) =25,f (7) = 40, thus obtaining f (n) =f (n-1) +f (n-3) +f (n-4), n>3. Then the recursive relationship can be used to find the loop section to solve.

Complexity analysis--time complexity: O (n), spatial complexity: O (n)

Attach the AC code:


#include <iostream> #include <cstdio> #include <string> #include <cmath> #include <iomanip > #include <ctime> #include <climits> #include <cstdlib> #include <cstring> #include < algorithm>using namespace std;typedef unsigned int ui;typedef long long ll;typedef unsigned long long ull;typedef long Double Ld;const double PI = 3.14159265;const double E = 2.71828182846;const int mod = 2005;const int look = 1000;int fib[l Ook] = {1, 2, 4, 6, 9, 15};int Main () {Ios::sync_with_stdio (false); int loop;for (int i=6; i<=look; i++) {Fib[i] = (fib[i- 1]+FIB[I-3]+FIB[I-4])%2005;if (fib[i] = = 2 && fib[i-1] = = 1) {loop = I-1;break;}} int L;while (cin >> L) {cout << fib[l%loop] << Endl;} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 2440 DNA

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.