HDU1560 DNA sequence 迭代深搜IDA*
2017-01-14 19:08
381 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1560
题意是给你一些DNA串,要你输出一串字符串使得它能包含所有的DNA串的序列,要求其字典序最小,长度最短。
代码:
题意是给你一些DNA串,要你输出一串字符串使得它能包含所有的DNA串的序列,要求其字典序最小,长度最短。
代码:
#include<cstdio> #include<cstring> #include<string> #include<queue> #include<cmath> #include<vector> #include<map> #include<stack> #include<iostream> #include<algorithm> using namespace std; #define ll long long #define inf 0x3f3f3f3f #define scanfprint() freopen("input.txt","r",stdin) #define printfprint() freopen("output.txt","w",stdout) #define mem(a,b) memset(a,b,sizeof(a)) const int spot=1000+10; const int edge=100000+10; const int maxn=10; const double pi=acos(-1.0); const int mod=1e9+7; const double ips=0.000001; int n,m,a[maxn],len[maxn],have[maxn],maxlen=0; char s[maxn][maxn],ss[maxn]="ACGT"; bool flag=0; int f() { int ans=0,i; for(i=1; i<=n; i++) ans=max(ans,len[i]-have[i]); return ans; } void dfs(int maxlen) { int i,j; int h=f(); if(!h) { flag=1; return; } if(h>maxlen) return ; bool ok=0; int temp[maxn]; memcpy(temp,have,sizeof(temp)); for(i=1; i<=4; i++) { for(j=1; j<=n; j++) if(s[j][have[j]]==ss[i-1]) ok=1,have[j]++; if(ok) { dfs(maxlen-1); if(flag) return ; } memcpy(have,temp,sizeof(have)); } } int main() { int nn,i,j; scanf("%d",&nn); while(nn--) { maxlen=0; flag=0; scanf("%d",&n); for(i=1; i<=n; i++) { scanf("%s",s[i]); len[i]=strlen(s[i]); have[i]=0; maxlen=max(maxlen,len[i]); } for(;;) { dfs(maxlen); if(flag) break; else maxlen++; } printf("%d\n",maxlen); } return 0; }
相关文章推荐
- poj2871 A Simple Question of Chemistry(水题)
- 巧用weui.gallery(),点击图片后预览图片
- AI(三):微信与luis结合(上)
- UIImage添加水印(Logo+文字)
- JBWEB002004: More than the maximum number of request parameters (GET plus POST) for a single request
- 关于小米2S从MIUI7降级和recovery的绕路之旅
- gRPC helloworld service, RESTful JSON API gateway and swagger UI
- error: conflicting types for 'RTASSERTVAR'
- 浅谈UE4引擎
- 用Vue中遇到的问题和处理方法(一)
- 在controller中用@value读取配置文件的方法
- 模拟Vue之数据驱动3
- wait queue 2
- 模拟Vue之数据驱动2
- easyui-datagrid获取行和列数据
- restful Api 风格契约设计器:Swagger-editor和swagger-ui的应用
- SQL Server ->> SQL Server 2016新特性之 --- Query Store
- 1056. Mice and Rice (25)-PAT甲级真题(queue的用法)
- wait queue 1
- 第一个Hello Vue!