题目链接:点击打开链接

题目大意:给出n个字符串。要求组合后的串最短

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;
char str[12][22] ;
char s[300] , s1[300] ;
int vis[12] , min1 , n , l[12];
void dfs(int cnt,int k) {
//printf("%d %d\n", cnt, k) ;
if( cnt >= min1 ) return ;
if(k == n) {
min1 = min(min1,cnt) ;
return ;
}
int i , p , q , num ;
for(i = 0 ; i < n ; i++) {
if( vis[i] ) continue ;
vis[i] = 1 ;
for(p = max(0,cnt-l[i]) ; p <= cnt ; p++) {
for(q = p ; q < cnt ; q++)
if( str[i][q-p] != s[q] ) break ;
if( q == cnt ) {
num = cnt ;
for(q = q-p ; q < l[i] ; q++)
s[num++] = str[i][q] ;
break ;
}
}
dfs(num,k+1) ;
vis[i] = 0 ;
}
return ; }
int main() {
int t , i ;
scanf("%d", &t) ;
while( t-- ) {
scanf("%d", &n) ;
for(i = 0 ; i < n ; i++) {
scanf("%s", str[i]) ;
l[i] = strlen(str[i]) ;
}
min1 = 1000 ;
memset(s,0,sizeof(s)) ;
memset(vis,0,sizeof(vis)) ;
dfs(0,0) ;
printf("%d\n", min1) ;
}
return 0 ;
}

poj1699--Best Sequence(dfs+剪枝)的更多相关文章

  1. POJ 3009 DFS+剪枝

    POJ3009 DFS+剪枝 原题: Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16280 Acce ...

  2. *HDU1455 DFS剪枝

    Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  3. poj 1724:ROADS(DFS + 剪枝)

    ROADS Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10777   Accepted: 3961 Descriptio ...

  4. DFS(剪枝) POJ 1011 Sticks

    题目传送门 /* 题意:若干小木棍,是由多条相同长度的长木棍分割而成,问最小的原来长木棍的长度: DFS剪枝:剪枝搜索的好题!TLE好几次,终于剪枝完全! 剪枝主要在4和5:4 相同长度的木棍不再搜索 ...

  5. DFS+剪枝 HDOJ 5323 Solve this interesting problem

    题目传送门 /* 题意:告诉一个区间[L,R],问根节点的n是多少 DFS+剪枝:父亲节点有四种情况:[l, r + len],[l, r + len - 1],[l - len, r],[l - l ...

  6. HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)

    Counting Cliques Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  7. HDU 5937 Equation 【DFS+剪枝】 (2016年中国大学生程序设计竞赛(杭州))

    Equation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  8. LA 6476 Outpost Navigation (DFS+剪枝)

    题目链接 Solution DFS+剪枝 对于一个走过点k,如果有必要再走一次,那么一定是走过k后在k点的最大弹药数增加了.否则一定没有必要再走. 记录经过每个点的最大弹药数,对dfs进行剪枝. #i ...

  9. poj 1011 Sticks (DFS+剪枝)

    Sticks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 127771   Accepted: 29926 Descrip ...

  10. poj 1564 Sum It Up | zoj 1711 | hdu 1548 (dfs + 剪枝 or 判重)

    Sum It Up Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Sub ...

随机推荐

  1. 基于aspectj的aop的操作

    1.引入相关的jar包 2.建两个类 public class Book { public void add(){ System.out.println("add-----------&qu ...

  2. hdoj--2119--Matrix(最小点覆盖)

    Matrix Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  3. 【NOIP 2009】 靶形数独

    [题目链接] https://www.luogu.org/problemnew/show/P1074 [算法] 搜索 + 剪枝 [代码] #include<bits/stdc++.h> u ...

  4. Reorder List 最典型的linkedlist题目

    https://oj.leetcode.com/problems/reorder-list/ Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder ...

  5. [Hacker] 端口大全

    一 .端口大全 端口:0 服务:Reserved 说明:通常用于分析操作系统.这一方法能够工作是因为在一些系统中“0”是无效端口,当你试图使用通常的闭合端口连接它时将产生不同的结果.一种典型的扫描,使 ...

  6. php 微信支付 回调通知不停的坑

    微信支付已完工,最后有点小问题就是微信的回调会重复9次 第一步: $return = "success"; echo $return; 不管用 第二步: $return = &qu ...

  7. TPL详解、使用

    使用时注意点 private async void button5_Click(object sender, EventArgs e) { /* string i1 = await F1Async() ...

  8. 文件操作:Directory,File,FielStream、StreamRead和StreamWriter的使用

    Directory文件类,File,FielStream.StreamRead和StreamWriter的使用 (转载) 创建一个新文件 Directory.CreateDirectory(@&quo ...

  9. javascript实现选项卡切换的4种方法

    方法一:for循环+if判断当前点击与自定义数组是否匹配 <html lang="en"> <head> <meta charset="UT ...

  10. HDFS开发中的一些问题(逐步补充)

    1.windows操作系统下运行时报:Failed to locate the winutils binary in the hadoop binary path   java.io.IOExcept ...