Codevs 2980 买帽子 dp(LIS)
来源:互联网 发布:怎么取消备案域名 编辑:程序博客网 时间:2024/05/17 00:17
Codevs 2980 买帽子
对于一个字符串的最长对称子序列,就是它和它反串的最长公共子序列
我看了DQS的题解
代码:(char 数组实现)
#include <cstdio>#include <cstring>#include <iostream>#include <cstdlib>#include <algorithm>using namespace std;#define MAXLEN (500+5)#define MAXN (100+10)struct STR{ char s[MAXLEN]; int k, len;}c[MAXN];char zs[MAXLEN];int dp[MAXLEN][MAXLEN];bool cmp(STR a, STR b){ if(a.k != b.k) return a.k > b.k; if(a.len != b.len) return a.len < b.len; for(int i = 1; i <= a.len; i ++) if(a.s[i] != b.s[i]) return a.s[i] < b.s[i]; return 0;}int main(){ int n; cin >> n; for(int q = 1; q <= n; q ++) { scanf("%s", c[q].s+1); c[q].len = strlen(c[q].s+1); for(int i = 1; i <= c[q].len; i ++) zs[c[q].len-i+1] = c[q].s[i]; memset(dp, 0, sizeof(dp)); for(int i = 1; i <= c[q].len; i ++) for(int j = 1; j <= c[q].len; j ++) if(c[q].s[i] == zs[j]) dp[i][j] = max(max(dp[i-1][j], dp[i][j-1]), dp[i-1][j-1]+1); else dp[i][j] = max(dp[i-1][j], dp[i][j-1]); c[q].k = dp[c[q].len][c[q].len]; } sort(c+1, c+n+1, cmp); for(int i = 1; i <= n; i ++) { for(int j = 1; j <= c[i].len; j ++) printf("%c", c[i].s[j]); printf("\n"); } return 0;}
0 0
- Codevs 2980 买帽子 dp(LIS)
- codevs 2980 买帽子(DP)
- <序列DP>codevs 2980 买帽子
- Codevs 2980 买帽子
- Codevs 2980 买帽子
- codevs 2980 买帽子 题解报告
- codeves 2980 买帽子 字符串dp
- 2980 买帽子
- CDOEVS 2980 买帽子
- 买帽子
- 买帽子
- 买帽子
- 【codevs2980】买帽子
- code vs 买帽子
- codevs2980买帽子
- 百度笔试- 买帽子
- 牛客网 买帽子
- [编程题] 买帽子
- Spring 注解 Demo
- CreateThread,_beginthread与AfxbeginThread 的区别 (转载自jogholy的博客)
- C#获取方法名
- maven学习笔记
- bzoj 2541: [Ctsc2000]冰原探险 (bfs+建图)
- Codevs 2980 买帽子 dp(LIS)
- PL/SQL存储函数,存储过程
- Docker容器内多进程管理(一)-Supervisor
- [算法题] 人民币大小写转换(阿拉伯数字和汉字转换)
- 页面标题导航宽度自适应并左右两端有背景修饰图案
- 卷积算子计算方法(卷积运算)
- Explicit——谨慎定义隐式类型转换函数
- CodeForces 429B Working out 递推
- 证明$A^TAX = A^Tb$有公共解