题目: 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. AWS SQS DOC AND RUBY DEMO

    # Amazon SQS 搜集整理aws sqs 的文档以及使用Ruby demo ## Amazon Simple Queue Service (SQS) 是一个可伸缩且可靠的消息传递框架,能够使用 ...

  2. Java解惑五:类之谜

    本文是依据JAVA解惑这本书,做的笔记.电子书见:http://download.csdn.net/detail/u010378705/7527721 谜题46 函数重载的问题. JAVA重载解析过程 ...

  3. mac上SVN项目管理,提示被锁定的解决方法

    问题 mac上SVN项目管理,提示被锁定.不能commit.也不能update.提示 clean the working copy and then. .. 解决方法 watermark/2/text ...

  4. android91 代码注册广播接收者

    Activity: package com.itheima.register; import android.os.Bundle; import android.app.Activity; impor ...

  5. 从 setNeedsLayout 说起

    本文从 setNeedsLayout 这个方法说起,分享与其相关的 UIKit 视图交互.使用场景等内容. UIKit 为 UIView 提供了这些方法来进行视图的更新与重绘: public func ...

  6. MyJFrame(文本)界面的建立

    import java.awt.Color;import java.awt.Component;import java.awt.Container;import java.awt.FlowLayout ...

  7. Git之路--2

  8. Android源码分析:HeaderViewListAdapter

    http://bj007.blog.51cto.com/1701577/643568 对于手机开发,我一直坚持的是“用iPhone的方式开发iPhone应用,用Android的方式开发Android应 ...

  9. c#调用c++ dll(一)

    首先来说说c++中的dll 核心的一些知识 比较大的应用程序都由很多模块组成,这些模块分别完成相对独立的功能,它们彼此协作来完成整个软件系统的工作.可能存在一些模块的功能较为通用,在构造其它软件系统时 ...

  10. Webservice学习之——即时发布与定制发布

    一.工具 myEclipse tomcat  6.0 以上版本 axis-bin-1_4.zip 二.即时发布 1.解压 axis-bin-1_4.zip 2.axis-bin-1_4.zip\axi ...