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)后就蒙了
甚么鬼?
敢情这是高精度?
貌似不对…
一万年后,机智的我发现这应该有循环出现的情况(因为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.
- poj 2440 DNA
- POJ 2440 DNA
- poj-2440-DNA
- 【POJ 2440】 Dna
- POJ 2440 DNA
- POJ 2440 DNA(递推)
- POJ 1007 DNA Sorting
- poj 1007 DNA Sorting
- POJ 1007 DNA Sorting
- POJ-1007 DNA Sorting
- 【POJ】1007 DNA Sorting
- POJ-1007:DNA Sorting
- poj 1007 DNA Sorting
- POJ 1007 DNA Sorting
- POJ 1007 DNA Sorting
- poj 1007 DNA Sorting
- poj 2778 DNA Sequence
- poj 3691 DNA repair
- Java学习的基础概念和知识点
- Java对象克隆(Clone)及Cloneable接口
- Postgresql 配置文件详解
- Android 小知识点汇总(更新中)
- org.apache.struts.action.InvalidCancelException异常解决方法
- POJ 2440 DNA
- 关于ListView的显示问题
- The number of method references in a .dex file cannot exceed 64K
- LeetCode 121. Best Time to Buy and Sell Stock
- windows安装配置mysql-5.7.13-winx64方法
- maven如何手动导入ojdbc6.jar或ojdbc14
- Mondrian 4 测试的简单demo(Saiku简单测试Schema文件)
- python网络天气爬虫
- HDU 4408 Minimum Spanning Tree(最小生成树计数)