可能没有完全读懂题意。

个人觉得

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. 【Spark】Spark的Standalone模式安装部署

    Spark执行模式 Spark 有非常多种模式,最简单就是单机本地模式,还有单机伪分布式模式,复杂的则执行在集群中,眼下能非常好的执行在 Yarn和 Mesos 中.当然 Spark 还有自带的 St ...

  2. In Mind

    [做项目时要懂得调试,不能一遇到问题.错误,就开始寻求帮助,先要学着自己解决,对错误进行分析,逐一排查,最终找到错误原因,然后剩下的如何解决就不是大问题了.]!!!

  3. echart初体验 动态加载数据

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  4. 深度CTR预估模型中的特征自动组合机制演化简史 zz

    众所周知,深度学习在计算机视觉.语音识别.自然语言处理等领域最先取得突破并成为主流方法.但是,深度学习为什么是在这些领域而不是其他领域最先成功呢?我想一个原因就是图像.语音.文本数据在空间和时间上具有 ...

  5. JDK1.9-新特性

    1. Java平台级模块系统 该特性使Java9最大的一个特性,Java提供该功能的主要的动机在于,减少内存的开销,JVM启动的时候,至少会有30~60MB的内存加载,主要原因是JVM需要加载rt.j ...

  6. [svc]jdk1.7.0_13(系列)下载url

    蛋疼了,这个版本,找了老半天没找到 最后是同事找到的 http://download.oracle.com/otn/java/jdk/7u13-b20/jdk-7u13-linux-x64.tar.g ...

  7. [iOS]delegate和protocol

    转自:http://haoxiang.org/2011/08/ios-delegate-and-protocol/ 今天上班和同事讨论工程怎么组织的时候涉及到这个话题.iOS开发上对delegate使 ...

  8. 利用C#的指针编写都一个简单链表

    using System; namespace UnsafeTest { unsafe struct link { public int x; public link* next; } class P ...

  9. 讲一下 Spring的事务传播特性

    1. PROPAGATION_REQUIRED:  如果存在一个事务,则支持当前事务.如果没有事务则开启 2. PROPAGATION_SUPPORTS:  如果存在一个事务,支持当前事务.如果没有事 ...

  10. linux时间同步-NTP服务

    作者:曹世军链接:https://www.zhihu.com/question/30252609/answer/108840850来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注 ...