codevs 3301 Square words 题解报告
2016-11-08 11:11
357 查看
噫。
题目描述 Description
定义square words为:
1.长度为偶数。
2.前一半等于后一半。
比如abcabc和aaaa都是square words,但是abcabcab和aaaaa都不是。
现在有一个长度为n的字符串,求至少要删掉多少个字符,使得剩下的字符串是square words。
输入描述 Input Description
第一行包含一个正整数n。
第二行一个长度为n的字符串,仅包含小写字母
输出描述 Output Description
仅包含一个整数,表示最少需要删掉的字符数
样例输入 Sample Input
11
abaccdaabcd
样例输出 Sample Output
3
数据范围及提示 Data Size & Hint
【样例说明】
abaccdaabcd
【数据规模】
对于40%的数据,n ≤ 20;
对于100%的数据,n ≤ 500。
啊啊啊啊啊啊啊啊啊啊啊啊啊啊
题目水 数据水 N三方 可以过 啊哈哈
嗯
枚举中点,对两侧求LCS;
取最大,
嗯。
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<vector> #include<queue> #include<map> #include<set> #include<stack> #include<cstdlib> #include<string> #include<bitset> #include<iomanip> #include<deque> #define INF 1000000000 #define fi first #define se second #define N 100005 #define P 1000000007 #define debug(x) cerr<<#x<<"="<<x<<endl #define MP(x,y) make_pair(x,y) using namespace std; int n,m,ans=2147483647; char s[510]; int f[501][501]; inline int get_num() { int num = 0; char c; bool flag = false; while ((c = getchar()) == ' ' || c == '\n' || c == '\r'); if (c == '-') flag = true; else num = c - '0'; while (isdigit(c = getchar())) num = num * 10 + c - '0'; return (flag ? -1 : 1) * num; } int lcs(int x) { memset(f,0,sizeof(f)); for(int i=1;i<x;i++) { for(int j=1;j<=n-x+1;j++) { if(s[i]==s[j+x-1]) { f[i][j]=f[i-1][j-1]+1; }else { f[i][j]=max(f[i-1][j],f[i][j-1]); } } } return f[x-1][n-x+1]; } int main() { cin>>n; for(int i=1;i<=n;i++) { cin>>s[i]; } for(int i=2;i<=n;i++) { ans=min(ans,n-lcs(i)*2); } cout<<ans; }
相关文章推荐
- codevs 1065 01字符串 题解报告
- code[vs]3301 Square words
- codevs 2488 绿豆蛙的归宿 题解报告
- codevs 1060 搞笑世界杯 题解报告
- code[vs]3301 Square words
- codevs 1058 合唱队形 题解报告
- Code[VS] 3301 Square words
- codevs 1507 酒厂选址 题解报告
- codevs 1961 躲避大龙 题解报告
- codevs 1009 产生数 题解报告
- codevs 1045 回文数 题解报告
- codevs 1228 苹果树 题解报告
- codevs 2833 奇怪的梦境 题解报告
- codevs 1019 集合论与图论 题解报告
- Square words(codevs 3301)
- codevs 1036 商务旅行 题解报告
- codevs 2618 核电站问题 题解报告
- 【日常学习】【最短路Dijkstra】codevs1069 usaco回家 题解
- [题解][codevs] 1959 拔河比赛
- codevs 1079 回家 Floyd 解题报告