博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1583 DNA Assembly(暴力模拟)
阅读量:4138 次
发布时间:2019-05-25

本文共 2756 字,大约阅读时间需要 9 分钟。

DNA Assembly

Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 213 Accepted Submission(s): 88
Problem Description
Farmer John has performed DNA sequencing on his prize milk-producing cow, Bessie DNA sequences are ordered lists (strings) containing the letters 'A', 'C', 'G', and 'T'.
As is usual for DNA sequencing, the results are a set of strings that are sequenced fragments of DNA, not entire DNA strings. A pair of strings like 'GATTA' and 'TACA' most probably represent the string 'GATTACA' as the overlapping characters are merged, since they were probably duplicated in the sequencing process.
Merging a pair of strings requires finding the greatest overlap between the two and then eliminating it as the two strings are concatenated together. Overlaps are between the end of one string and beginning of another string, NOT IN THE MIDDLE OF A STRING.
By way of example, the strings 'GATTACA' and 'TTACA' overlap completely. On the other hand, the strings 'GATTACA' and 'TTA' have no overlap at all, since the matching characters of one appear in the middle of the other, not at one end or the other. Here are some examples of merging strings, including those with no overlap:
GATTA + TACA -> GATTACA
TACA + GATTA -> TACAGATTA
TACA + ACA -> TACA
TAC + TACA -> TACA
ATAC + TACA -> ATACA
TACA + ACAT -> TACAT
Given a set of N (2 <= N <= 7) DNA sequences all of whose lengths are in the range 1..7, find and print length of the shortest possible sequence obtainable by repeatedly merging all N strings using the procedure described above. All strings must be merged into the resulting sequence.
Input
The input consists of multiple test cases.
Each test case :
Line 1: A single integer N
Lines 2..N+1: Each line contains a single DNA subsequence
End of file.
Output
For each pair of input output the length of the shortest possible string obtained by merging the subsequences. It is always possible – and required – to merge all the input strings to obtain this string.
Sample Input
4GATTATAGGATCGACGCAT
Sample Output
13   
Hint
Hint
Explanation of the sample: Such string is "CGCATCGATTAGG".
Source
/*题目意思:让你拼接字符串,使长度最少; 思路:法一:由于N好小,直接暴力模拟,对N个字符串进行全排列,若可以,则算出结果长度;法二:图论:第i个字符串作为点i,枚举i到其他点是否可以拼接,若可以,则有向边,权值为公共长度标记入度,和邻接表vector对入度为0的作为起点枚举,回朔标记点是否访问过,累加权值最大sum所有字符串的长度-最大公共长度=结果 *//*用的法1  不知为何wa?  知道的求告知*/#include 
#include
#include
using namespace std;string s[10];int a[10];int map[10][10]; int n,sum,re;inline int check(int x,int y){ int i,j; for(i=0;i
>n){ sum=0; //字符串总长 re=-99999999; //最长公共部分 for(int i=0;i
>s[i]; sum+=s[i].length(); a[i]=i; } for(int i=0;i

转载地址:http://cdmvi.baihongyu.com/

你可能感兴趣的文章
Mysql中下划线问题
查看>>
Xcode 11 报错,提示libstdc++.6 缺失,解决方案
查看>>
idea的安装以及简单使用
查看>>
Windows mysql 安装
查看>>
python循环语句与C语言的区别
查看>>
vue 项目中图片选择路径位置static 或 assets区别
查看>>
vue项目打包后无法运行报错空白页面
查看>>
Vue 解决部署到服务器后或者build之后Element UI图标不显示问题(404错误)
查看>>
element-ui全局自定义主题
查看>>
facebook库runtime.js
查看>>
vue2.* 中 使用socket.io
查看>>
openlayers安装引用
查看>>
js报错显示subString/subStr is not a function
查看>>
高德地图js API实现鼠标悬浮于点标记时弹出信息窗体显示详情,点击点标记放大地图操作
查看>>
初始化VUE项目报错
查看>>
vue项目使用安装sass
查看>>
HTTP和HttpServletRequest 要点
查看>>
在osg场景中使用GLSL语言——一个例子
查看>>
laravel 修改api返回默认的异常处理
查看>>
laravel事务
查看>>