HDU1560(迭代加深搜索)
DNA sequence
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1914 Accepted Submission(s): 946
For example, given "ACGT","ATGC","CGTT" and "CAGT", you can make a sequence in the following way. It is the shortest but may be not the only one.
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN=;
struct Node{
char s[MAXN];
int len,top;
}DNA[MAXN];
int n;
char buf[]={'A','C','G','T'};
bool dfs(int l,int limit)
{
int remain=;
for(int i=;i<n;i++)
{
if(DNA[i].len-DNA[i].top>remain)
{
remain=DNA[i].len-DNA[i].top;
}
}
if(remain==) return true;
if(remain+l>limit) return false; //重要剪枝一 for(int i=;i<;i++)
{
bool tag=false;
int vis[MAXN]={};
for(int j=;j<n;j++)
{
if(buf[i]==DNA[j].s[DNA[j].top])
{
vis[j]=;
DNA[j].top++;
tag=true;
}
}
if(!tag) continue;//重要剪枝二
if(dfs(l+,limit))
{
return true;
}
for(int j=;j<n;j++)
{
if(vis[j])
{
DNA[j].top--;
}
}
}
return false;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
int limit=;
for(int i=;i<n;i++)
{
scanf("%s",DNA[i].s);
DNA[i].len=strlen(DNA[i].s);
DNA[i].top=;
limit=max(limit,DNA[i].len);
}
while(!dfs(,limit))
{
for(int i=;i<n;i++)
{
DNA[i].top=;
}
limit++;
}
printf("%d\n",limit);
}
return ;
}
HDU1560(迭代加深搜索)的更多相关文章
- POJ1129Channel Allocation[迭代加深搜索 四色定理]
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14601 Accepted: 74 ...
- BZOJ1085: [SCOI2005]骑士精神 [迭代加深搜索 IDA*]
1085: [SCOI2005]骑士精神 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1800 Solved: 984[Submit][Statu ...
- 迭代加深搜索 POJ 1129 Channel Allocation
POJ 1129 Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14191 Acc ...
- 迭代加深搜索 codevs 2541 幂运算
codevs 2541 幂运算 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 从m开始,我们只需要6次运算就可以计算出 ...
- HDU 1560 DNA sequence (IDA* 迭代加深 搜索)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1560 BFS题解:http://www.cnblogs.com/crazyapple/p/321810 ...
- UVA 529 - Addition Chains,迭代加深搜索+剪枝
Description An addition chain for n is an integer sequence with the following four properties: a0 = ...
- hdu 1560 DNA sequence(迭代加深搜索)
DNA sequence Time Limit : 15000/5000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total ...
- 迭代加深搜索 C++解题报告 :[SCOI2005]骑士精神
题目 此题根据题目可知是迭代加深搜索. 首先应该枚举空格的位置,让空格像一个马一样移动. 但迭代加深搜索之后时间复杂度还是非常的高,根本过不了题. 感觉也想不出什么减枝,于是便要用到了乐观估计函数(O ...
- C++解题报告 : 迭代加深搜索之 ZOJ 1937 Addition Chains
此题不难,主要思路便是IDDFS(迭代加深搜索),关键在于优化. 一个IDDFS的简单介绍,没有了解的同学可以看看: https://www.cnblogs.com/MisakaMKT/article ...
随机推荐
- 八、golang文本操作、json协议
一.终端读写 操作终端相关文件语句常量,go所有的都是接口 os.Stdin:标准输入 os.Stdout:标准输入,只要实现输出这个接口,打印到终端, os.Stderr:标准错误输出 os.Ope ...
- 用nodejs实现读取文件操作
//如果不是全局就得引入fs成员 const fs = require("fs"); //fs 核心模块中提供了一个 fs.readFile方法,来读取指定目录下的文件 //fs. ...
- juniper设置共享上网(注意事项)
注意:出去的 策略 ,勾上 NAT 选项
- 文件系统中跳转【TLCL】
pwd - Print name of current working directory cd - Change directory ls - List directory contents Lin ...
- nodejs mysql 操作数据库方法二
node.js 开发指南 – Node.js 连接 MySQL 并进行数据库操作 通常在NodeJS开发中我们经常涉及到操作数据库,尤其是 MySQL ,作为应用最为广泛的开源数据库则成为我们的首选, ...
- 使用Properties读写属性文件
import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.Properties; /*Prop ...
- 使用roboware创建工作空间
1.打开终端,启动roboware软件: $roboware-studio 2.在欢迎使用的页面点新建工作区,工作区的名字建议写为:catkin_ws,路径放在home文件夹或者任意你想放的文件夹中. ...
- python递归中的return"陷阱"
在做一道练习题(参照下篇博文<在当前目录下递归的查找包含指定字符串的文件>)的时候,发现函数中的return的值竟然是None,百思不得其解,尝试化繁为简,用以下的简单的代码验证了一下 问 ...
- 配置SSH密码登录
在客户端生成公钥: ssh-keygen –t rsa 生成的公钥默认位置在~/.ssh/目录 把公钥上传到服务器端: scp id_rsa.pub root@ip地址:文件保存路径 cat id_r ...
- poj 1836 LIS变形
题目链接http://poj.org/problem?id=1836 Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submiss ...