可能没有完全读懂题意。

个人觉得

acca

aa

答案应该是4.

然后就是dp了。。这题数据量小很多方法都可以,数据也水暴力据说都能过。。

还有就是我竟然没有用扩展kmp优化下。。。 太无耻了,我是因为找扩展kmp的题才来看这题的。

Best Sequence
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 4217   Accepted: 1668

Description

The twenty-first century is a biology-technology developing century. One of the most attractive and challenging tasks is on the gene project, especially on gene sorting program. Recently we know that a gene is made of DNA. The nucleotide bases from which DNA is built are A(adenine), C(cytosine), G(guanine), and T(thymine). Given several segments of a gene, you are asked to make a shortest sequence from them. The sequence should use all the segments, and you cannot flip any of the segments.

For example, given 'TCGG', 'GCAG', 'CCGC', 'GATC' and 'ATCG', you can slide the segments in the following way and get a sequence of length 11. It is the shortest sequence (but may be not the only one). 

Input

The first line is an integer T (1 <= T <= 20), which shows the number of the cases. Then T test cases follow. The first line of every test case contains an integer N (1 <= N <= 10), which represents the number of segments. The following N lines express N segments, respectively. Assuming that the length of any segment is between 1 and 20.

Output

For each test case, print a line containing the length of the shortest sequence that can be made from these segments.

Sample Input

1
5
TCGG
GCAG
CCGC
GATC
ATCG

Sample Output

11

Source

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <sstream>
#include <iostream>
using namespace std;
#define INF 0x3fffffff int n;
char save[][];
char g[][];
int mark[];
int dp[][][];//状态压缩
int top=;
int sum[][]; int check(char s[],char t[])
{
int len=strlen(s);
int len1=strlen(t);
int cnt=;
int flag=;
for(int i=;i<len1;i++)
{
int tmp=i;
while(tmp<len1&&s[cnt]==t[tmp])
{
cnt++;
tmp++;
if(cnt==len)
{
flag=;
break;
}
}
cnt=;
}
return flag;
} int main()
{
//freopen("//home//chen//Desktop//ACM//in.text","r",stdin);
//freopen("//home//chen//Desktop//ACM//out.text","w",stdout);
int T;
scanf("%d",&T);
while(T--)
{
memset(mark,,sizeof(mark));
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%s",save[i]);
//////////////
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
if(i==j) continue;
if(mark[j]==&&check(save[i],save[j])==)
{
mark[i]=;
break;
}
}
}
top=; for(int i=;i<n;i++)
{
if(mark[i]==)
{
strcpy(g[top],save[i]);
top++;
}
} //////////////////////////////先做个预处理比较方便吧
memset(sum,,sizeof(sum)); for(int i=;i<top;i++)
for(int j=;j<top;j++)
{
if(i==j) continue;
int len=strlen(g[i]);
int len1=strlen(g[j]);
for(int k=min(len,len1)-;k>=;k--)
{
int flag=;
for(int i1=;i1<k;i1++)
if(g[i][len-k+i1]!=g[j][i1])
{
flag=;
break;
}
if(flag==)
{
sum[i][j]=len1-k;
break;
}
else sum[i][j]=len1;
}
} //这样就求出sum了
////////////////然后剩下的就是不会互相影响的了 for(int ii=;ii<=;ii++)
for(int i=;i<=;i++)
for(int j=;j<;j++)
dp[ii][i][j]=INF; for(int i=;i<top;i++)
{
int len=strlen(g[i]);
dp[][i][ (<<i) ] = len;
} for(int ii=;ii<top;ii++)
{
for(int j=;j<top;j++)
{
for(int k=;k<(<<top);k++)
{
if(dp[ii-][j][k]==INF) continue;
for(int i=;i<top;i++)
{
if( ( k&(<<i) )== )
{
//在之前没有出现过的时候..
dp[ii][i][(k|(<<i))]=min(dp[ii][i][( k|(<<i) )],dp[ii-][j][k]+sum[j][i]);
}
}
}
}
} int mi=INF;
for(int i=;i<top;i++)
for(int j=;j<(<<top);j++)
mi=min(dp[top-][i][j],mi);
printf("%d\n",mi);
}
return ;
}

poj1699(状态压缩dp)的更多相关文章

  1. hoj2662 状态压缩dp

    Pieces Assignment My Tags   (Edit)   Source : zhouguyue   Time limit : 1 sec   Memory limit : 64 M S ...

  2. POJ 3254 Corn Fields(状态压缩DP)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4739   Accepted: 2506 Descr ...

  3. [知识点]状态压缩DP

    // 此博文为迁移而来,写于2015年7月15日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w6jf.html 1.前 ...

  4. HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP

    题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...

  5. DP大作战—状态压缩dp

    题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...

  6. 状态压缩dp问题

    问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...

  7. BZOJ-1226 学校食堂Dining 状态压缩DP

    1226: [SDOI2009]学校食堂Dining Time Limit: 10 Sec Memory Limit: 259 MB Submit: 588 Solved: 360 [Submit][ ...

  8. Marriage Ceremonies(状态压缩dp)

     Marriage Ceremonies Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  9. HDU 1074 (状态压缩DP)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:有N个作业(N<=15),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ...

随机推荐

  1. Thread.sleep(0)的作用

    我们可能经常会用到 Thread.Sleep 函数来使线程挂起一段时间.那么你有没有正确的理解这个函数的用法呢?思考下面这两个问题: 假设现在是 2008-4-7 12:00:00.000,如果我调用 ...

  2. Java 变长參数Varargs

    Varargs (variable arguments)可变长參数是Java 1.5引入的特性. 方法的形參如print(String ... s),实參为随意数目的值. public class V ...

  3. Timer使用

    1. Timer简介 Timer是jdk中提供的一个定时器工具,使用的时候会在主线程之外起一个单独的线程执行指定的计划任务,可以指定执行一次或者反复执行多次. 通过创建Timer对象,然后调用Time ...

  4. VSCode集成Git代码管理

    一.安装和配置VSCode与Git 1.下载Git并安装: https://git-scm.com/download/ 2.下载VSCode并进行安装: https://code.visualstud ...

  5. Linux 基础学习(第一节)

    IP地址的配置 配置临时IP地址 ifconfig etho 192.168.0.91 255.255.255.0 图形化下面配置IP地址: 重启网卡服务: shell环境配置网卡信息 必备的参数 关 ...

  6. unity, Destroy注意事项

    Destroy不是立即发生作用,而是推迟到帧末,所以下面代码是错误的: void OnTriggerEnter(Collider other){   if (other.gameObject.tag  ...

  7. Atitit. IE8.0 显示本地图片预览解决方案 img.src=本地图片路径无效的解决方案

    Atitit. IE8.0 显示本地图片预览解决方案 img.src=本地图片路径无效的解决方案 1. IE8.0 显示本地图片 img.src=本地图片路径无效的解决方案1 1.1. div来完成  ...

  8. 让 Vivado有Zybo Board的配置文件

    Zybo Board开发记录: 让 Vivado有Zybo Board的配置文件 由 judyzhong 于 星期三, 07/13/2016 - 10:41 发表 本文转载自:coldnew's bl ...

  9. vivado设计三:一步一步生成自己的自定义IP核

    开发环境:xp  vivado2013.4 基于AXI-Lite的用户自定义IP核设计 这里以用户自定义led_ip为例: 1.建立工程 和设计一过程一样,见vivado设计一http://blog. ...

  10. 河南省第七届ACM程序设计大赛赛后总结

    我们学校ACM集训开始于4月5号(清明节),5月25日在郑州解放军信息工程大学举办,集训耗时50天,但是感觉效果还行,但是也不是太好:我们也已经尽力了,虽然说只拿了个银牌,每份收获的背后,都会有辛勤的 ...