TOJ 2641 Gene

来源:互联网 发布:阿里云选择镜像 编辑:程序博客网 时间:2024/06/05 10:21

Gene

时间限制(普通/Java):1000MS/10000MS     运行内存限制:65536KByte

描述

How can millions of different and complex structures be built using only a few simple building blocks? Just ask your DNA. DNA (short for deoxyribonucleic acid) spells out the genetic codes of millions of species, using just four molecules: adenine (A), guanine (G), thymine (T), and cytosine (C). These molecules are called nucleotide bases. Different sequences of nucleotide bases are what define each species.
Within this coil of DNA lies all the information needed to produce everything in the human body. A strand of DNA may be millions, or billions, of base-pairs long. Different segments of the DNA molecule code for different characteristics in the body. A Gene is a relatively small segment of DNA that codes for the synthesis of a specific protein. This protein then will play a structural or functional role in the body. A chromosome is a larger collection of DNA that contains many genes and the support proteins needed to control these genes.


Now , we give you the Sequence of some genes, which code for different proteins. And then we give every protein a score.here comes your problem,if we give you a chromosome in sequence , of course it can code many proteins, can you arrange which proteins it code , with the object to get The largest score (two proteins can not be overlap).

输入

There will be several testcases. For each testcase, the first line is an integer N(1 < N ≤ 100,000), the number of the genes we will give you. Then followed N lines , each line contains a string S(the lenth of S is no more than 10), the sequence of the gene , and an integer C, the score of the protein the gene code. The last line of each testcase is a string (the length of this string is no more than 1000), describes the sequence of the chromosome.

输出

For each testcase , output the largest score in the sample’s format.

样例输入

4AATG 3AT 2GCGG 3GG 2AATGCGG3A 1C 1G 1T

样例输出

Case 1: 5Case 2: 0

dp[i]表示到字符串第i个位置时最大的得分

首先for从1到len

对于每个i在for j 从1到10(因为每个片段最长卫10)然后截取从i开始长度为j的子串 那么dp[i+j] = max(dp[i+j],dp[i]+k)其中k是截取片段的值

看代码

#include <stdio.h>#include <string.h>#include <map>#include <string>#include <iostream>using namespace std;int dp[1010];int main(){string str,s;char a[20];int n,i,x,k,j,cas = 1;while(scanf("%d",&n)!=EOF){map <string,int>m;memset(dp,0,sizeof(dp));for(i = 0;i < n; i++){scanf("%s %d",a,&x);m[a] = x; }cin >> s;n = s.size();for(i = 0;i < n; i++){for(j = 1;j <= 10; j++){if(i + j <= n){str = s.substr(i,j);k = dp[i] + m[str];if(dp[i + j] < k)dp[i + j] = k;}}}int max = 0;for(i = 1;i <= n; i++)if(dp[i] > max)max = dp[i];printf("Case %d: %d\n",cas++,max);}return 0;} 


 

原创粉丝点击