hdu 1080 Human Gene Functions 简单dp
来源:互联网 发布:sql语句修改字段值 编辑:程序博客网 时间:2024/05/22 15:52
传送门 http://acm.hdu.edu.cn/showproblem.php?pid=1080
题意:
- 给出两串 dna 序列, 每个碱基之间匹配得分不同要求匹配出最大得分
分析:
- dp[i][j] 代表匹配到第一串第 i 个和第二串第 j 个时的最大得分
- dp[i][j] = max(dp[i-1][j-1] + match(i, j), dp[i][j-1] - match(i, j-1) + match(0, j-1) + match(i, j), dp[i-1][j] - match(i-1, j) + match(i-1, 0) + match(i, j));
#include <stdio.h>#include <iostream>#include <cstring>#include <string>using namespace std;const int MAX = 111, INF = 1 << 16 - 1;const int mch[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, 0};int dp[MAX][MAX], mp[2][MAX], T, n[2];char c;int max(int a, int b) {return a > b ? a : b;}int judge(char c) { if (c == 'A') return 0; if (c == 'C') return 1; if (c == 'G') return 2; if (c == 'T') return 3; if (c == '-') return 4; return -1;}void getin() { for (int i = 0; i < 2; ++i) { scanf ("%d", n+i); c = 0; while (true) { c = getchar(); if (c == 'A' || c == 'T' || c == 'G' || c == 'C') break; } mp[i][1] = judge(c); for (int j = 2; j <= n[i]; ++j) { c = getchar(); mp[i][j] = judge(c); } } for (int i = 0; i < MAX; ++i) for (int j = 0; j < MAX; ++j) dp[i][j] = -INF; dp[0][0] = 0;}void DP() { for (int i = 0; i <= n[0]; ++i) { for (int j = 0; j <= n[1]; ++j) { if (i && j) dp[i][j] = max(dp[i-1][j-1] + mch[mp[0][i]][mp[1][j]], dp[i][j]); if (i) dp[i][j] = max(dp[i-1][j] - mch[mp[0][i-1]][mp[1][j]] + mch[mp[0][i-1]][4] + mch[mp[0][i]][mp[1][j]], dp[i][j]); if (j) dp[i][j] = max(dp[i][j-1] - mch[mp[0][i]][mp[1][j-1]] + mch[4][mp[1][j-1]] + mch[mp[0][i]][mp[1][j]], dp[i][j]); } } printf("%d\n", dp[n[0]][n[1]]);}int main() { freopen("in.t", "r", stdin); scanf("%d", &T); while (T--) { getin(); DP(); } return 0;}
咕咕咕
2017-10-10
阅读全文
0 0
- hdu 1080 Human Gene Functions 简单dp
- hdu 1080 Human Gene Functions--DP
- hdu 1080 Human Gene Functions(dp)
- HDU 1080 Human Gene Functions dp
- hdu 1080 dp Human Gene Functions
- hdu 1080 Human Gene Functions (dp)
- HDU 1080 Human Gene Functions (DP)
- (DP)HDU 1080 Human Gene Functions
- hdu 1080 Human Gene Functions(LCS&DP)
- HDU - 1080 Human Gene Functions DP
- hdu 1080 Human Gene Functions dp
- 【DP|LCS】HDU-1080 Human Gene Functions
- hdu 1080 Human Gene Functions 线性dp
- HDU 1080 Human Gene Functions DP -
- Hdu 1080 Human Gene Functions(DP)
- hdu 1080 Human Gene Functions
- HDU 1080 Human Gene Functions
- HDU 1080 Human Gene Functions
- 解决eclipse在线安装插件缓慢问题
- Excel表的导出数据
- IRF540应用DC-DC电路设计
- java总结
- 移动端焦点轮播图 完整代码 bootstrap框架版本
- hdu 1080 Human Gene Functions 简单dp
- PTA 6-11 求自定类型元素序列的中位数
- Idea中Tomcat启动时日志乱码
- STM32F4 FPU简单设置
- T
- 设计模式【过滤器模式Filter Pattern】
- C#中重写(override)和覆盖(new)的区别
- 安装和使用 nvm 与 npm
- 电脑高手都在用的办公软件,你还不赶紧试试?