cv2980(LCS)
来源:互联网 发布:seo外链在线群发 编辑:程序博客网 时间:2024/06/15 19:10
题目链接
分析:
求字符串的最长回文串就是将字符串取反然后求两个串的最长公共子序列
还记得这道题吗
然而cv上的这道题并没有说明元素互异
我们就不能保证转换出一个n级别的字符串
所以干脆朴素算法
tip
对称系数k是指最长对称子序列的长度,非最长对称子串的长度
字符串的数组要开到1000
自己在下面拍,没有任何错误
交上去真的就是一直WA
找不到任何错误
扔一个学姐的标程吧
这里写代码片#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;char s[101][510],s1[5100],s2[5100];int f[510][510],n;struct node{ int bh,k,l;};node str[501];int cmp(const node &a,const node &b){ if (a.k>b.k) return 1; else if (a.k<b.k) return 0; else { int i=0; while (s[a.bh][i]==s[b.bh][i]&&i<a.l-1&&i<b.l-1) i++; if (s[a.bh][i]<s[b.bh][i]) return 1; else if (s[a.bh][i]>s[b.bh][i]) return 0; if (a.l<b.l) return 1; else return 0; }}void doit(int bh){ int i,j,k,ans=0,l,s; memset(f,0,sizeof(f)); int len=strlen(s1); for (i=0;i<len;i++) s2[i]=s1[len-i-1]; for (i=0;i<len;i++) for (j=0;j<len;j++) { if (s1[i]==s2[j]) f[i][j]=f[i-1][j-1]+1; else f[i][j]=max(f[i-1][j],f[i][j-1]); } str[bh].k=f[len-1][len-1];}int main(){ scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%s",&s[i]),str[i].bh=i,str[i].l=strlen(s[i]); for (int i=1;i<=n;i++) { memset(s1,'\0',sizeof(s1)); strcpy(s1,s[i]); doit(i); } sort(str+1,str+1+n,cmp); for (int i=1;i<=n;i++) printf("%s\n",s[str[i].bh]); return 0;}
阅读全文
0 0
- cv2980(LCS)
- 【HankerRank】LCS Returns(巧妙LCS)
- lcs(dp)
- poj1080(LCS变形)
- pojAGTC(LCS,DP)
- Nearest Sequence(lcs)
- Common Subsequence(LCS)
- Lcs(模板)
- POJ1159:Palindrome(LCS)
- poj 1159 (LCS)
- Common Subsequence (LCS)
- LCS
- LCS
- lcs
- LCS
- LCS
- LCS
- LCS
- 【codevs 1204】寻找子串位置
- 开始在csdn上写博客
- Eclipse自动生成返回值对象的快捷键是什么?
- 【胡策 9.16】Loi 队内胡策 Day1
- Mybatis学习总结
- cv2980(LCS)
- 爬取京东图书价格信息分析
- easyui datagrid 实现单个单元格提交业务
- 使用matplotlib绘制动态图
- 用python爬取小说信息(简易版)
- 工作中常用的sql语句
- Qt 学习之路 2(4):信号槽
- c++STL链表模板使用
- Leetcode451. 对字符出现频率进行排序