zoj 1027

ZOJ 1027
/*
zoj 1027 poj 1080 思路:
三种状态,取最大值:
s1[i]和s2[j]配 :dp[i-1][j-1]+cost[my[s1[i]]][my[s2[j]]];
s1[i]和‘-‘ 配: dp[i-1][j]+cost[my[s1[i]]][my[‘-‘]];
s2[j]和‘-‘ 配: dp[i][j-1]+cost[my[‘-‘]][my[s2[j]]];
注意边界:
d[i][0]= cost[my[s1[i]]][my[‘-‘]]+dp[i-1][0]; 只能全部和‘-‘配,
同理: dp[0][j]=cost[my[‘-‘]][my[s2[j]]]+dp[0][j-1];
*/

#include <iostream>
#include <map>
#include <cstring>
#include <string>
using namespace std;
int cost[5][5]={{5,-1,-2,-1,-3},{-1,5,-3,-2,-4},{-2,-3,5,-2,-2},{-1,-2,-2,5,-1},{-3,-4,-2,-1,-100000005}};
int dp[1005][1005];
string s1,s2;
map<char,int> my;
int main(int argc, char *argv[])
{
int t,i,n,j,m;
my[‘A‘]=0; my[‘C‘]=1; my[‘G‘]=2; my[‘T‘]=3; my[‘-‘]=4;
cin>>t;
while(t--)
{
cin>>n>>s1>>m>>s2;
s1=‘0‘+s1; s2=‘0‘+s2;
dp[0][0]=0;
for(i=1;i<=n;i++)
dp[i][0]=cost[my[s1[i]]][my[‘-‘]]+dp[i-1][0];
for(j=1;j<=m;j++)
dp[0][j]=cost[my[‘-‘]][my[s2[j]]]+dp[0][j-1];
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
int t1,t2,t3;
t1=dp[i-1][j-1]+cost[my[s1[i]]][my[s2[j]]];
t2=dp[i-1][j]+cost[my[s1[i]]][my[‘-‘]];
t3=dp[i][j-1]+cost[my[‘-‘]][my[s2[j]]];
t1=max(t1,t2); t1=max(t1,t3);
dp[i][j]=t1;
}
cout<<dp[n][m]<<endl;
}
return 0;
}

zoj 1027,布布扣,bubuko.com

时间: 2025-01-04 15:23:57

zoj 1027的相关文章

zoj 1027 Human Gene Functions

Human Gene Functions Time Limit: 2 Seconds      Memory Limit: 65536 KB It is well known that a human gene can be considered as a sequence, consisting of four nucleotides, which are simply denoted by four letters, A, C, G, and T. Biologists have been

zoj题目分类

饮水思源---zoj 转载自:http://bbs.sjtu.edu.cn/bbscon,board,ACMICPC,file,M.1084159773.A.html 注:所有不是太难的题都被归成了“简单题”,等到发现的时候已经太晚了,我太死脑筋 了……:( 有些题的程序我找不到了,555……:( SRbGa的题虽然都很经典……但是由于其中的大部分都是我看了oibh上的解题报告后做 的,所以就不写了…… 题目排列顺序没有规律……:( 按照个人感觉,最短路有的算做了DP,有的算做了图论. 有些比较

HustOJ - 1027

1 #include<iostream> 2 #include<string> 3 using namespace std; 4 int main() 5 { 6 int n, i, f, j; 7 string s; 8 char t; 9 10 cin >> n; 11 12 for(i = 1; i <= n; i++) 13 { 14 cin >> s; 15 t = s[0]; 16 f = 0; 17 for(j = 0; j < s

(全排列)Ignatius and the Princess II -- HDU -- 1027

链接: http://acm.hdu.edu.cn/showproblem.php?pid=1027 Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5822    Accepted Submission(s): 3433 Problem Description Now our h

概率dp ZOJ 3640

Help Me Escape Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3640 Appoint description:  System Crawler  (2014-10-22) Description Background     If thou doest well, shalt thou not be accepted? an

zoj 2156 - Charlie&#39;s Change

题目:钱数拼凑,面值为1,5,10,25,求组成n面值的最大钱币数. 分析:dp,01背包.需要进行二进制拆分,否则TLE,利用数组记录每种硬币的个数,方便更新. 写了一个 多重背包的 O(NV)反而没有拆分快.囧,最后利用了状态压缩优化 90ms: 把 1 cents 的最后处理,其他都除以5,状态就少了5倍了. 说明:貌似我的比大黄的快.(2011-09-26 12:49). #include <stdio.h> #include <stdlib.h> #include <

ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 最小生成树 Kruskal算法

题目链接:ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 Building a Space Station Time Limit: 2 Seconds      Memory Limit: 65536 KB You are a member of the space station engineering team, and are assigned a task in the construction process of the statio

ZOJ 3607 Lazier Salesgirl (贪心)

Lazier Salesgirl Time Limit: 2 Seconds      Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling. She can sell the i-th customer a piece of bread for price pi. But she is so lazy

ZOJ - 2243 - Binary Search Heap Construction

先上题目: Binary Search Heap Construction Time Limit: 5 Seconds      Memory Limit: 32768 KB Read the statement of problem G for the definitions concerning trees. In the following we define the basic terminology of heaps. A heap is a tree whose internal n