題目鏈接

題意 : 將幾個片段如圖所示方法縮成一個序列,求出最短這個序列。

思路 : 其實我也不知道怎麼做。。。。。看網上都用了DP。。。。。但是我不會。。。。。這個DP不錯,還有用KMP+状压DP做的

 //
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string> using namespace std; string str[] ;
int dp[][],ans ,n,vis[]; void f(int i,int j)
{
int len1 = str[i].size() ;
int len2 = str[j].size() ;
int s = ;
for(int k = ; k <= len1 && k <= len2 ; k++)
{
bool flag = true ;
for(int h = ; h < k ; h++)
{
if(str[i][len1-k+h] != str[j][h])
{
flag = false ;
break ;
}
}
if(flag == true)
s = k ;
}
dp[i][j] = len2-s ;
} void dfs(int now,int ceng,int len)
{
if(len >= ans) return ;
if(ceng == n-) ans = min(ans,len) ;
for(int i = ; i <= n ; i++)
{
if(!vis[i])
{
vis[i] = ;
dfs(i,ceng+,len+dp[now][i]) ;
vis[i] = ;
}
}
}
int main()
{
int T;
scanf("%d",&T) ;
while(T--)
{
scanf("%d",&n) ;
for(int i = ; i <= n ; i++)
cin>>str[i] ;
for(int i = ; i <= n ; i++)
for(int j = ; j <= n ; j++)
if(i != j) f(i,j) ;
memset(vis,,sizeof(vis)) ;
ans = ;
for(int i = ; i <= n ; i++)
{
vis[i] = ;
dfs(i,,str[i].size()) ;
vis[i] = ;
}
printf("%d\n",ans) ;
}
return ;
}

POJ 1699 Best Sequence(DFS)的更多相关文章

  1. POJ 3009-Curling 2.0(DFS)

    Curling 2.0 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12158   Accepted: 5125 Desc ...

  2. 题解报告:poj 1321 棋盘问题(dfs)

    Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子 ...

  3. POJ 2251 Dungeon Master(dfs)

    Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...

  4. POJ - 1019 Number Sequence (思维)

    https://vjudge.net/problem/POJ-1019 题意 给一串1 12 123 1234 12345 123456 1234567 12345678 123456789 1234 ...

  5. [ACM] POJ 3740 Easy Finding (DFS)

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16202   Accepted: 4349 Description Give ...

  6. POJ 2386——Lake Counting(DFS)

    链接:http://poj.org/problem?id=2386 题解 #include<cstdio> #include<stack> using namespace st ...

  7. POJ 1321 棋盘问题(dfs)

    传送门 棋盘问题 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 38297   Accepted: 18761 Descri ...

  8. POJ 1321 棋盘问题 (dfs)

    在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C. ...

  9. POJ:2386 Lake Counting(dfs)

    Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 40370   Accepted: 20015 D ...

随机推荐

  1. 如何在Mac下使用TF/SD 卡制作Exynos 4412 u-boot启动盘

    /** ****************************************************************************** * @author    Maox ...

  2. 转:Java HashMap实现详解

    Java HashMap实现详解 转:http://beyond99.blog.51cto.com/1469451/429789 1.    HashMap概述:    HashMap是基于哈希表的M ...

  3. Turn.js 实现翻书效果的学习与总结

    最近CTO给我分配了一个移动端H5开发的任务,主要功能是需要实现翻书效果,我听过主要需求后,当时是呀!!!接下来自己尝试使用fullPage.js和Swiper来实现翻书效果,结果效果都不是非常的理想 ...

  4. nginx自启动脚本

    #!/bin/bash # #Startup script for Nginx - this script starts and stops the nginx daemon # # chkconfi ...

  5. 启动另外一个activity,并返回结果

    欢迎大家光临我的小店:http://clkk.taobao.com 大致步骤: 1.启动另外一个Activity,这里称子Activity: 2.子Activity通过setResult方法设置返回结 ...

  6. 【笔记】W3C CSS关键属性

    white-space属性: white-space 属性设置如何处理元素内的空白. 可能的值 值 描述 normal 默认值,合并所有空格,换行符会被浏览器忽略 pre 空白会被浏览器保留.其行为方 ...

  7. hdu 5545 The Battle of Guandu spfa最短路

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5545 题意:有N个村庄, M 个战场: $ 1 <=N,M <= 10^5 $; 其中曹 ...

  8. 编辑器未包含main类型解决方法

    将文件移到 src 这个 Java Source Folder 下面去,现在在外面的 java 文件不会被当成一个需要编译的类,eclipse 不会编译 Java Source Folder 外面的任 ...

  9. C++中的struct和class的区别

    C++中的struct对C中的struct进行了扩充,它已经不再只是一个包含不同数据类型的数据结构了,它已经获取了太多的功能.struct能包含成员函数吗? 能!struct能继承吗? 能!!stru ...

  10. MVC中的几个问题汇总

    1.The model backing the 'XXXXDBContext' context has changed since the database was created. Either m ...