poj 1080 DP
来源:互联网 发布:优化调整方案 编辑:程序博客网 时间:2024/06/09 22:44
dp【i】【j】表示s1前i个与s2前j个匹配获得的最大值
那么可以 i与j匹配 或者 i与‘-’匹配 或者jyu‘-’匹配
AC代码如下:
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;#define MAX 0x3f3f3f3fchar s1[200], s2[200];int length1, length2;int score[200][200];int dp[200][200];int DFS( int pos1, int pos2 ){ if( pos1 == -1 && pos2 == -1 ){ return 0; } if( pos1 != -1 && pos2 != -1 && dp[pos1][pos2] != -1 ){ return dp[pos1][pos2]; } int ans = -MAX; if( pos1 != -1 ) ans = max( ans, score[(int)s1[pos1]]['-'] + DFS( pos1 - 1, pos2 ) ); if( pos2 != -1 ) ans = max( ans, score['-'][(int)s2[pos2]] + DFS( pos1, pos2 - 1 ) ); if( pos1 != -1 && pos2 != -1 ) ans = max( ans, score[(int)s1[pos1]][(int)s2[pos2]] + DFS( pos1 - 1, pos2 - 1 ) ); return dp[pos1][pos2] = ans;}int main(){ score['A']['A'] = 5;score['A']['C'] = -1;score['A']['G'] = -2;score['A']['T'] = -1;score['A']['-'] = -3; score['C']['A'] = -1;score['C']['C'] = 5;score['C']['G'] = -3;score['C']['T'] = -2;score['C']['-'] = -4; score['G']['A'] = -2;score['G']['C'] = -3;score['G']['G'] = 5;score['G']['T'] = -2;score['G']['-'] = -2; score['T']['A'] = -1;score['T']['C'] = -2;score['T']['G'] = -2;score['T']['T'] = 5;score['T']['-'] = -1; score['-']['A'] = -3;score['-']['C'] = -4;score['-']['G'] = -2;score['-']['T'] = -1;score['-']['-'] = -0x3f3f3f; int T; scanf( "%d", &T ); while( T-- ){ scanf( "%d%s", &length1, s1 ); scanf( "%d%s", &length2, s2 ); memset( dp, -1, sizeof( dp ) ); cout << DFS( length1 - 1, length2 - 1 ) << endl; } return 0;}
0 0
- 【DP】 POJ 1080
- POJ 1080 (DP)
- POJ 1080 dp
- poj 1080 DP
- poj 1080 DP
- poj 1080 dp
- POJ 1080 DP
- poj 1080 (DP)
- poj 1080 dp(sequence alignment)
- poj dp
- 【dp】POJ
- 【dp】POJ
- [DP] POJ
- [DP] POJ
- [DP] POJ
- 【dp】POJ
- POJ 1080 Human Gene Functions DP(LCS)
- poj 1080 一道经典的dp题
- centos 6.3 64位下安装mysql5.5.36
- JSP内置对象
- java公开密钥(N,e)的生成算法
- 读程序员编程艺术第二章---字符串包含问题
- 线段树练习
- poj 1080 DP
- c里对象
- 联合查询与多表查询基础详解
- win764位系统安装32位jdk java环境变量设置
- ACM进阶之路
- 线段树模板(插入,搜索)
- android震动伴随铃声渐增功能的实现
- 第二周作业:“RSA”、“数字签名”、“公钥”、“DES“的解释; 判断一个正整数是否为质数的算法;随机生成一个n bit位的长整数
- GStreamer基础教程11——调试工具