There are given two strings, A and B. An expansion of some string X is a string created by adding or inserting any number (zero, one or more) of blanks anywhere in the string, or in the begining or the end of the string. Eg., if the string X is ‘abcbcd’, then the strings 'abcb-cd', '-a-bcbcd-' and 'abcb-cd-' are expansions of the string X (blanks are denoted by the character ‘-‘).

If A1 is an expansion of the string A, and B1 is and expansion of the string B, and if A1 and B1 are of the same length, then we define the distance of the strings A1 and B1 as the sum of the distances of the characters on the same positions in these strings. We define the distance of two characters as the absolute difference of their ASCII codes, except the distance of the blank and another character, which is given (and equal for all characters).

You are to write a program which finds the expansions A1 and B1 of strings A and B, that have the smallest difference.

Input

The first line of the input file consists of the string A, and the second line of string B. They are consisted only of lower case characters of the english alphabet (a-z), and the number of characters in any of the strings is less than or equal to 2000.

The third line consists of an integer K, 1 ≤ K ≤ 100, the distance of the blank and the other characters.

Output

The first only line of the input file should consist of the smallest distance as defined in the text of the task.

Sample

  1. Input:
  2. cmc
  3. snmn
  4. 2
  5.  
  6. output:
  7. 10
  1. Input:
  2. koiv
  3. ua
  4. 1
  5.  
  6. output:
  7. 5
  1. input:
  2. mj
  3. jao
  4. 4
  5.  
  6. output:
  7. 12
  8.  
  9. 题目大意:添加空格使得两个字符串的 距离值最小。
    类似于 lcs 写法
    题目中 k 字符和空格之间的距离。 这里的‘距离’是题目中定义的
  1. /* ***********************************************
  2. Author :guanjun
  3. Created Time :2016/9/4 18:45:31
  4. File Name :1001.cpp
  5. ************************************************ */
  6. #include <iostream>
  7. #include <cstring>
  8. #include <cstdlib>
  9. #include <stdio.h>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <queue>
  13. #include <set>
  14. #include <map>
  15. #include <string>
  16. #include <math.h>
  17. #include <stdlib.h>
  18. #include <iomanip>
  19. #include <list>
  20. #include <deque>
  21. #include <stack>
  22. #define ull unsigned long long
  23. #define ll long long
  24. #define mod 90001
  25. #define INF 0x3f3f3f3f
  26. #define maxn 10010
  27. #define cle(a) memset(a,0,sizeof(a))
  28. const ull inf = 1LL << ;
  29. const double eps=1e-;
  30. using namespace std;
  31. priority_queue<int,vector<int>,greater<int> >pq;
  32. struct Node{
  33. int x,y;
  34. };
  35. struct cmp{
  36. bool operator()(Node a,Node b){
  37. if(a.x==b.x) return a.y> b.y;
  38. return a.x>b.x;
  39. }
  40. };
  41.  
  42. bool cmp(int a,int b){
  43. return a>b;
  44. }
  45. char s[],t[];
  46. int dp[][];
  47. int main()
  48. {
  49. #ifndef ONLINE_JUDGE
  50. freopen("in.txt","r",stdin);
  51. #endif
  52. //freopen("out.txt","w",stdout);
  53. int k;
  54. scanf("%s %s %d",s+,t+,&k);
  55. int n=strlen(s+);
  56. int m=strlen(t+);
  57. //dp[0][0]=0;
  58. for(int i=;i<=n;i++)dp[i][]=k*i;
  59. for(int i=;i<=m;i++)dp[][i]=k*i;
  60. for(int i=;i<=n;i++){
  61. for(int j=;j<=m;j++){
  62. dp[i][j]=min(dp[i-][j-]+abs(s[i]-t[j]),min(dp[i-][j],dp[i][j-])+k);
  63. }
  64. }
  65. cout<<dp[n][m]<<endl;
  66. return ;
  67. }

MBLAST - BLAST的更多相关文章

  1. the comment lines of the blast tabular format

    进行Blast比对,用参数-m 6 可以以列表的方式输出结果,结果中从左到右每一列的意义分别是: [00] Query id [01] Subject id [02] % identity [03] ...

  2. Blast本地化

    转载]Blast本地化:使用Blastall进行数据库比对 (2012-02-13 21:25:31)   用blastall进行序列比对 blastall是最常用的blast程序之一,其功能非常强大 ...

  3. 本地blast用法

    格式化数据库: makeblastdb -in db.fasta -dbtype prot -parse_seqids -out dbname 参数说明: -in:待格式化的序列文件 -dbtype: ...

  4. BLAST - 序列数据库搜索

    我生信入门,老师就要求我学好blast比对,说得也确实是很有道理,是个人都知道比对是最基本的东西,现在再想想那老师的建议,也只能呵呵一笑. 北大生物信息公开课有一章专门讲得序列数据库搜索,可以好好看看 ...

  5. Blast使用详解

    Blast,全称Basic Local Alignment Search Tool,即"基于局部比对算法的搜索工具",由Altschul等人于1990年发布.Blast能够实现比较 ...

  6. 本人开发的JavaWeb急速框架Blast上线了

    JAVA 急速WEB框架Blast --对JavaWeb的学习性框架,参考了spring的实现 --阅读Blast源码可以快速掌握JavaWeb常用技术和方法论,并付诸实践 Blast 是基于 Jav ...

  7. linux blast

    建库 减压后,改名为blast,并在blas目录在建立db文件1,建立数据库makeblastdb -in db.fasta -dbtype nucl(prot) -parse_seqids -has ...

  8. 关于生物项目上的blast和viroblast

    最近要做一个跟生物有关的项目,隔行如隔山呀,好多工具以前都没听过,blast分到我头上啦,查查,查查 BLAST (Basic Local Alignment Search Tool)是一套在蛋白质数 ...

  9. Blast

    NCBI 教程:https://www.ncbi.nlm.nih.gov/books/NBK279681/ 本地使用 blast 的步骤 1. 构建本地数据库索引 $makeblastdb -in h ...

随机推荐

  1. Python游戏开发:pygame游戏开发常用数据结构

    一.数组与列表 数组可以理解为简化的列表.像我们之前使用的pygame.sprite.Group这样的精灵组,也是一个列表.列表的元素是可变的,它具有添加.删除.搜索.排序等多种方法. 1.一维列表 ...

  2. 并发编程学习笔记(8)----ThreadLocal的使用及源码分析

    1. ThreadLocal的理解 ThreadLocal,顾名思义,就是线程的本地变量,ThreadLocal会为每个线程创建一个本地变量副本,使得使用ThreadLocal管理的变量在多线程的环境 ...

  3. vue中的input使用e.target.value赋值的问题

    很久不写博客了... vue中对表单的处理,相对原生js,增加了一个双向绑定的语法糖:v-model.官方文档里有一段: v-model 会忽略所有表单元素的 value.checked.select ...

  4. Spring事物不回滚

    今天发现个自己的bug,仔细排查后,发现根本原因我在service方法中抛出的异常被控制层的方法捕获了,所以后台页面也只是出现个错误提示,而数据却没有回滚. 解决方式:对自己抛出的异常使用try ca ...

  5. 诊断:ORA-01919: role ‘PLUSTRACE’ does not exist

    如下错误 SQL> grant plustrace to scott; grant plustrace to scott * ERROR at line 1: ORA-01919: role ' ...

  6. HDU - 4803 - Poor Warehouse Keeper (思维)

    题意: 给出x,y两个值分别代表x个物品,总价为y 有两种变化: 1.使总价+1,数量不变 2.数量+1,总价跟着变化 (y = y + y / x) 思路: 给出目标x,y,计算最少变化次使数量变化 ...

  7. man中文手册安装

    转载自 https://www.cnblogs.com/fyc119/p/7116295.html man中文手册安装 下载源码 wget https://src.fedoraproject.org/ ...

  8. ubuntu jdk和tomcat配置

    先查看linux的版通过file /sbin/init命令,下载对应版本的jdk. 我的ubuntu是64位的(桌面系统),所以下载的是jdk-7u71-linux-x64.tar.gz 在home的 ...

  9. SSM+Shiro

    1) 表名:用户表(Sys_Users) Salt:盐(佐料).为避免被黑客等进行攻击(暴力密码破解),所以一般在注册用户信息时,系统会随机生成一个随机码.在验证时会将密码和随机码进行运算,以验证密码 ...

  10. noip模拟赛 花

    [问题描述]商店里出售n种不同品种的花.为了装饰桌面,你打算买m支花回家.你觉得放两支一样的花很难看,因此每种品种的花最多买1支.求总共有几种不同的买花的方案?答案可能很大,输出答案mod p的值. ...