【POJ 1080】 Human Gene Functions
【POJ 1080】 Human Gene Functions
相似于最长公共子序列的做法
dp[i][j]表示 str1[i]相应str2[j]时的最大得分
转移方程为
dp[i][j]=max(dp[i-1][j-1]+score[str1[i]][str2[j]],
max(dp[i-1][j]+score[str1[i]][‘-‘],dp[i][j-1]+score[‘-‘][str2[j]]) )
注意初始化0下标就好
代码例如以下:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int dp[101][101];
char a[102],b[102];
int sc['Z'+1]['Z'+1];
int main()
{
int t,aa,bb,i,j;
scanf("%d",&t);
sc['A']['A'] = sc['C']['C'] = sc['G']['G'] = sc['T']['T'] = 5;
sc['A']['C'] = sc['C']['A'] = sc['A']['T'] = sc['T']['A'] = sc['T']['-'] = -1;
sc['G']['A'] = sc['A']['G'] = sc['C']['T'] = sc['T']['C'] = sc['G']['T'] = sc['T']['G'] = sc['G']['-'] = -2;
sc['A']['-'] = sc['C']['G'] = sc['G']['C'] = -3;
sc['C']['-'] = -4;
while(t--)
{
scanf("%d %s %d %s",&aa,a+1,&bb,b+1);
dp[0][0] = 0;
for(i = 1; i <= bb; ++i) dp[0][i] = sc[b[i]]['-'] + dp[0][i-1];
for(i = 1; i <= aa; ++i) dp[i][0] = sc[a[i]]['-'] + dp[i-1][0];
for(i = 1; i <= aa; ++i)
{
for(j = 1; j <= bb; ++j)
{
dp[i][j] = max(dp[i-1][j-1] + sc[a[i]][b[j]],max(dp[i-1][j] + sc[a[i]]['-'],dp[i][j-1] + sc[b[j]]['-']));
}
}
printf("%d\n",dp[aa][bb]);
}
return 0;
}
【POJ 1080】 Human Gene Functions的更多相关文章
- POJ 1080:Human Gene Functions LCS经典DP
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18007 Accepted: ...
- 【poj1080】 Human Gene Functions
http://poj.org/problem?id=1080 (题目链接) 题意 给出两个只包含字母ACGT的字符串s1.s2,可以在两个字符串中插入字符“-”,使得s1与s2的相似度最大. Solu ...
- 杭电1080 J - Human Gene Functions
题目大意: 两个字符串,可以再中间任何插入空格,然后让这两个串匹配,字符与字符之间的匹配有各自的分数,求最大分数 最长公共子序列模型. dp[i][j]表示当考虑吧串1的第i个字符和串2的第j个字符时 ...
- poj 1080 ——Human Gene Functions——————【最长公共子序列变型题】
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17805 Accepted: ...
- poj 1080 Human Gene Functions(lcs,较难)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19573 Accepted: ...
- 【POJ 2195】 Going Home(KM算法求最小权匹配)
[POJ 2195] Going Home(KM算法求最小权匹配) Going Home Time Limit: 1000MS Memory Limit: 65536K Total Submiss ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- Human Gene Functions
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18053 Accepted: 1004 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
随机推荐
- 查询oracle数据库中当前数据库所有表的名称
http://www.cnblogs.com/hyq0002013/p/5948419.html select t.table_name from user_tables t;
- 使用Mybatis做批量插入
最近有个需求,将excel的数据导入的数据库的这个一个操作. 工作主要分为:解析excel,将excel中的数据单条循环插入数据库. 使用框架:mybatis+spring 使用过Mybatis的人都 ...
- 移动APP 支付宝快捷支付开发流程
[代码] [Java]代码 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ...
- ubantu16.04安装配置samba服务(原创)
1.安装samba服务 $ sudo apt-get install samba samba-common$ sudo apt-get install smbclient 如果你开启了防火墙,关闭: ...
- Codeforces Gym100952 A.Who is the winner? (2015 HIAST Collegiate Programming Contest)
A. Who is the winner? time limit per test 1 second memory limit per test 64 megabytes input stan ...
- Codeforces 891B - Gluttony
891B - Gluttony 题意 给出一个数字集合 \(a\),要求构造一个数组 \(b\) 为 \(a\) 的某个排列,且满足对于所有下标集合的子集 \(S=\{x_1,x_2,...,x_k\ ...
- Codeforces 863F - Almost Permutation
863F - Almost Permutation 题意 给出每个位置可以放的数字的范围,定义 \(cost = \sum_{i=1}^{n}(cnt(i))^2\) ,其中 \(cnt(i)\) 为 ...
- RPD Volume 168 Issue 4 March 2016 评论7-end
Shielding activation of petawatt laser facilities in Romania: a FLUKA preliminary evaluation Abstr ...
- [BZOJ2125]最短路(圆方树DP)
题意:仙人掌图最短路. 算法:圆方树DP,$O(n\log n+Q\log n)$ 首先建出仙人掌圆方树(与点双圆方树的区别在于直接连割边,也就是存在圆圆边),然后考虑点u-v的最短路径,显然就是:在 ...
- java源码阅读Object
1 类注释 Class {@code Object} is the root of the class hierarchy. Every class has {@code Object} as a s ...