poj——1080(dp)
来源:互联网 发布:java培训骗局 编辑:程序博客网 时间:2024/04/20 17:24
题目地址:http://poj.org/problem?id=1080
解析:dp[i][j]来由:
1.dp[i][j-1]转移,则‘-’和s2[j]匹配。
2.dp[i-1][j]转移,则s1[i]和‘-’匹配。
3.dp[i-1][j-1],则s1[i]和s2[j]匹配。三者取最大值即可。
#include <iostream>#include <cmath>#include <string>#include <cstring>#include <cstdlib>#include <ctime>#include <algorithm>#include <cstdio>#include <map>#include <vector>#include <set>#include <queue>#include <stack>using namespace std;typedef long long ll;#define INF 0x7fffffff#define MAX(a,b) a>b?a:b#define MIN(a,b) a>b?b:a#define N 103int len2,len1;int dp[N][N];char s1[N],s2[N];int match[N][N];void init(){match['A']['T']=-1;match['T']['A']=-1;match['A']['A']=5;match['T']['T']=5;match['A']['C']=-1;match['C']['A']=-1;match['A']['G']=-2;match['G']['A']=-2;match['C']['G']=-3;match['G']['C']=-3;match['G']['G']=5;match['C']['C']=5;match['C']['T']=-2;match['T']['C']=-2;match['T']['G']=-2;match['G']['T']=-2;match['A']['-']=-3;match['-']['A']=-3;match['-']['C']=-4;match['C']['-']=-4;match['G']['-']=-2;match['-']['G']=-2;match['-']['T']=-1;match['T']['-']=-1;}void solve(){int i,j;dp[0][0]=0;for(i=1;i<=len1;i++) dp[i][0]=dp[i-1][0]+match[s1[i]]['-']; for(i=1;i<=len2;i++) dp[0][i]=dp[0][i-1]+match['-'][s2[i]]; for(i=1;i<=len1;i++) for(j=1;j<=len2;j++) { dp[i][j]=max(dp[i-1][j-1]+match[s1[i]][s2[j]],max(dp[i-1][j]+match[s1[i]]['-'],dp[i][j-1]+match['-'][s2[j]])); } cout<<dp[len1][len2]<<endl;}int main(){ int t; cin>>t; init(); while(t--){ cin>>len1>>s1+1; cin>>len2>>s2+1; solve(); }return 0;}
- poj——1080(dp)
- poj 1080 (DP)
- POJ——1221(dp)
- poj——2063——Investment(dp)
- Poj 1742(男人八题——dp)
- POJ 3345——Bribing FIPA(树形DP)
- poj(1661)——Help Jimmy(二维dp)
- poj(2955)——Brackets(区间dp)
- POJ 2342——Anniversary party(树形dp基础)
- POJ——2479 Maximum sum(dp)
- 【POJ 1948】Triangular Pastures(dp—二维01背包)
- POJ 3378——Crazy Thairs(树状数组+dp+高精度)数据结构优化的DP
- POJ 1080-Human Gene Functions(DP)
- POJ 1080 Human Gene Functions(DP)
- 【DP】 POJ 1080
- POJ 1080 (DP)
- POJ 1080 dp
- poj 1080 DP
- 设备驱动-----Linux 设备和驱动加载的先后顺序
- 冒泡排序法,递归,JAVA版
- 选择排序法,循环,非递归,JAVA版
- note : PE file format study
- 日期类(java)
- poj——1080(dp)
- Linux2.6PCI驱动加载原理
- Java应用程序
- 概率算法求解圆周率π
- 几何方法---测试盒子 二
- TreeView
- ligh oj 1004 - Monkey Banana Problem
- hdu 2254 奥运
- C++模板类的继承1 :模板类继承模板类