题目: http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1305

这个题就是一个类似公共子串的dp,但是加了权值,其实还是很简单。

当匹配时相似程度是5,不匹配是-4,添加空隙是-7。那么dp[i][j]的值就来自于三个方式:

1、在s2[j]后添加空隙,那么相似程度就是dp[i][j-1] - 7

2、在s1[i]后添加空隙,那么相似程度就是dp[i-1][j] - 7

3、直接拿s1[i]和s2[j]匹配,如果匹配相似程度就是dp[i-1][j-1] + 5,如果不匹配相似程度就是dp[i-1][j-1] - 4

最后找一下字典序最小的,就是这样了。。。就是代码写的搓了一点。

 #include <stdio.h>
#include <string.h>
#include <algorithm> int dp[][];
char s1[], s2[][]; int main()
{
int t, ans = , x;
scanf("%s %d", s1, &t);
int n = strlen(s1);
for(int item = ; item < t; item++)
{
scanf("%s", s2[item]);
int m = strlen(s2[item]);
dp[][] = ;
for(int i = ; i <= n; i++)
dp[i][] = dp[i-][] - ;
for(int j = ; j <= m; j++)
dp[][j] = dp[][j-] - ;
for(int i = ; i <= n; i++)
{
for(int j = ; j <= m; j++)
{
dp[i][j] = std::max(std::max(dp[i-][j] - , dp[i][j-] - ), dp[i-][j-] + (s1[i-] == s2[item][j-] ? : -));
}
}
if(dp[n][m] > ans || (dp[n][m] == ans && strcmp(s2[x], s2[item]) > ))
{
ans = dp[n][m];
x = item;
}
}
printf("%d\n%s\n", ans, s2[x]);
return ;
}

SDUT 1305 查找基因序列问题 dp的更多相关文章

  1. usaco No Change, 2013 Nov 不找零(二分查找+状压dp)

    Description 约翰带着 N 头奶牛在超市买东西,现在他们正在排队付钱,排在第 i 个位置的奶牛需要支付 Ci 元.今天说好所有东西都是约翰请客的,但直到付账的时候,约翰才意识到自己没带钱,身 ...

  2. sdut 2840 Best string Orz~ (dp)

    题目 题意:有n1个o, n2个r, n3个z, n4个~, 求有多少种组合使 组合出来的字符串的任意前缀都满足 o的个数>=r的个数, r的个数>=z的个数 …………………… 思路:递推 ...

  3. Tyvj - 1305 单调队列优化dp

    今天有点头痛就不写具体细节了,贴完走人 #include<iostream> #include<algorithm> #include<cstdio> #inclu ...

  4. [ZJOI2010]基站选址,线段树优化DP

    G. base 基站选址 内存限制:128 MiB 时间限制:2000 ms 标准输入输出 题目类型:传统 评测方式:文本比较   题目描述 有N个村庄坐落在一条直线上,第i(i>1)个村庄距离 ...

  5. [LeetCode] Longest Increasing Subsequence 最长递增子序列

    Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...

  6. Longest Increasing Subsequence

    很久不写算法了== 写个东西练练手 最长上升子序列 输入n,然后是数组a[ ]的n个元素 输出最长上升子序列的长度 一.最简单的方法复杂度O(n * n) DP[ i ] 是以a[ i ] 为结尾的最 ...

  7. LIS

    五:LIS 概念 最长上升子序列(Longest Increasing Subsequence,LIS),在计算机科学上是指一个序列中最长的单调递增的子序列.比如一个序列31 2 6 3 8,他的最长 ...

  8. [LeetCode] 300. Longest Increasing Subsequence 最长递增子序列

    Given an unsorted array of integers, find the length of longest increasing subsequence. Example: Inp ...

  9. 【动态规划】ZZNU-OJ- 2054 : 油田

    2054 : 油田 (一个神奇的功能:点击上方文字进入相应页面) 时间限制:1 Sec 内存限制:32 MiB提交:49 答案正确:6 提交 状态 讨论区 题目描述 在太平洋的一片海域,发现了大量的油 ...

随机推荐

  1. Could not initialize class org.apache.log4j.LogManager 报错

    部署项目的时候,在windows下一切正常,但是在centos下就发生如下错误 Caused by: java.lang.ExceptionInInitializerError at com.dsid ...

  2. android92 aidl远程进程通信

    05项目RemoteService.java package com.itheima.remoteservice; //05项目 import com.itheima.remoteservice.Pu ...

  3. redis单机及其集群的搭建

    http://www.cnblogs.com/mouseIT/p/5288204.html

  4. Android(java)学习笔记147:textView 添加超链接(两种实现方式,,区别于WebView)

    1.方式1: LinearLayout layout = new LinearLayout(this); LinearLayout.LayoutParams params = new LinearLa ...

  5. Markdown 添加 Latex 数学公式

    添加公式的方法 Latex 数学公式语法 添加公式的方法 行内公式 $行内公式$ 行间公式 $$行间公式$$ Latex 数学公式语法 角标(上下标) 上标命令^{} 下标命令_{} 上下标命令用来放 ...

  6. Ubuntu14.04服务器安装ftp

    随笔记录一下Ubuntu下安装ftp 1.远程连接登录服务器之后,输入sudo apt-get update 并回车.如果不运行该命令,直接安装vsftpd,可能会出现有一些软件包无法下载. 2.输入 ...

  7. Eclipse SVN插件账号、密码修改

    操作系统:win7 svn插件:Window -> Preferences -> Team -> SVN 修改方式: 1,删除C:\Users\用户名\AppData\Roaming ...

  8. HDU-1002(简单大数加法)

    A + B Problem II Problem Description I have a very simple problem for you. Given two integers A and ...

  9. MySQL约束

    MySQL中约束保存在information_schema数据库的table_constraints中,可以通过该表查询约束信息: 常用5种约束: not null: 非空约束,指定某列不为空 uni ...

  10. 完全备份ORACLE数据库 并在另一台电脑上恢复

    由于最近有oracle的项目,需要把数据库在另外一台电脑里面配置一个一样的数据库用来测试开发用,之前是一直使用mssql,只需要附加或者还原就行,但是在oracle里面,就没有这么简单,但是也不难,操 ...