POJ 3080 Blue Jeans.
来源:互联网 发布:单片机专家 编辑:程序博客网 时间:2024/05/29 14:31
~~~~
题意就是找m组序列的最长连续公共子序列。
原来可以直接枚举。
从大到小枚举第一条序列长度的子序列,看下面m-1组序列是否有,找到的第一个必然是最优的(也是一个优化吧);
题目链接:http://poj.org/problem?id=3080
~~~~
#include<iostream>#include<cstring>#include<algorithm>#include<string>using namespace std;const int l=60;string str[10];int main(){ int T; cin>>T; while(T--) { int n; cin>>n; for(int i=0;i<n;i++) cin>>str[i]; int flag=0; string ans=""; for(int len=l;len>=3;len--) { for(int i=0;i+len-1<l;i++) { int ok=1; //枚举第一个序列由i始,长度为len的子序列。 string t=str[0].substr(i,len); for(int j=1;j<n;j++) { //若无: if(str[j].find(t)==string::npos) { ok=0; break; } } //注意要按字典序。 if(ok && (ans=="" || ans>t)) ans=t; } if(ans!="") { flag=1; break; } } if(flag) cout<<ans<<endl; else cout<<"no significant commonalities"<<endl; } return 0;}
0 0
- poj 3080 Blue Jeans
- poj 3080 Blue Jeans
- poj 3080 Blue Jeans
- poj 3080 Blue Jeans
- poj 3080 Blue Jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- Poj 3080 Blue Jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- poj 3080 Blue Jeans
- poj 3080 Blue jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- POJ 3080-Blue Jeans
- mysql ERROR 1265 (01000)故障解决一例
- sklearn模型持久化
- 狗狗40题~ (Volume C)
- LayoutManager不能被多个panel共用
- 06-2. 字符串字母大小写转换(10)
- POJ 3080 Blue Jeans.
- 《Linux设备节点创建》用户空间ueventd创建设备节点规则
- VSPD虚拟串口与流控实验
- Linux下面的压缩解压命令
- Android 简述touch事件中的MotionEvent
- poj Door Man(1300)
- 程序中的TODO、XXX、FIXME标签
- Abstract 抽象工厂模式
- 基于XMPP协议的Android IM研究(asmack)