3301 Square words

 时间限制: 1 s
 空间限制: 128000 KB
 题目等级 : 钻石 Diamond
 查看运行结果
 
 
题目描述 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。

分类标签 Tags 点此展开

 
题解:
O(n^3)的最长公共子序列,居然过了。
AC代码:
#include<cstdio>
#include<string>
#include<iostream>
using namespace std;
const int N=1e3+;
int n,f[N][N];
string s;
int ans=0x7fffffff;
inline int LCS(string a,string b){
int l1=a.length(),l2=b.length();
for(int i=;i<l1;i++){
for(int j=;j<l2;j++){
if(!i||!j) f[i][j]=a[i]==b[j];
else{
if(a[i]==b[j]) f[i][j]=f[i-][j-]+;
else f[i][j]=max(f[i-][j],f[i][j-]);
}
}
}
return f[l1-][l2-];
}
int main(){
cin>>n>>s;
for(int i=;i<n-;i++){
string a,b;
for(int j=;j<=i;j++) a+=s[j];
for(int j=i+;j<n;j++) b+=s[j];
int anc=LCS(a,b);
ans=min(ans,n-*anc);
}
printf("%d\n",ans);
return ;
}

3301 Square words的更多相关文章

  1. code[vs]3301 Square words

    暴力枚举+最长公共子序列 #include <iostream> #include <cstring> using namespace std; int dp[510][510 ...

  2. Square words(codevs 3301)

    题目描述 Description 定义square words为: 1.长度为偶数. 2.前一半等于后一半. 比如abcabc和aaaa都是square words,但是abcabcab和aaaaa都 ...

  3. [LeetCode] Matchsticks to Square 火柴棍组成正方形

    Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...

  4. [LeetCode] Valid Word Square 验证单词平方

    Given a sequence of words, check whether it forms a valid word square. A sequence of words forms a v ...

  5. [LeetCode] Valid Perfect Square 检验完全平方数

    Given a positive integer num, write a function which returns True if num is a perfect square else Fa ...

  6. [LeetCode] Maximal Square 最大正方形

    Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ret ...

  7. OPEN CASCADE Gauss Least Square

    OPEN CASCADE Gauss Least Square eryar@163.com Abstract. The least square can be used to solve a set ...

  8. OpenCascade Eigenvalues and Eigenvectors of Square Matrix

    OpenCascade Eigenvalues and Eigenvectors of Square Matrix eryar@163.com Abstract. OpenCascade use th ...

  9. Leetcode: Matchsticks to Square && Grammar: reverse an primative array

    Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...

随机推荐

  1. (转)Hibernate框架基础——一对多关联关系映射

    http://blog.csdn.net/yerenyuan_pku/article/details/52746413 上一篇文章Hibernate框架基础——映射集合属性详细讲解的是值类型的集合(即 ...

  2. Crash reporter

    A crash reporter is a software application whose function is to identify report crash details and to ...

  3. 个人作业Alpha项目测试

    这个作业属于哪个课程 软件工程原理 这个作业要求在哪里 作业要求 团队名称 TEAMPANTHER 这个作业的目标 每个同学必须选取非自己所在团队的3个项目进行测试. 在你所测试的项目的Alpha发布 ...

  4. vue过渡 & 动画---进入/离开 & 列表过渡

    (1)概述 Vue 在插入.更新或者移除 DOM 时,提供多种不同方式的应用过渡效果.包括以下工具: 在 CSS 过渡和动画中自动应用 class 可以配合使用第三方 CSS 动画库,如 Animat ...

  5. lombok无法解析log

    首先确认开发工具是否安装lombok,已安装的话打开lombok插件页,选择update, 然后重启idea.

  6. <MyBatis>入门一 HelloWorld

    1.HelloWorld 导入依赖 <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis --> <dependen ...

  7. db2 group by的疑惑。

    按借据号分组,显示每组的条数:

  8. buf.writeUInt8()函数详解

    buf.writeUInt8(value, offset[, noAssert]) value {Number} 需要被写入到 Buffer 的字节 offset {Number} 0 <= o ...

  9. 有哪些可以节省chrome内存的扩展插件?

    不知道从什么时候开始,chrome浏览器就这样不知不觉的超过IE浏览器成为全球第一大浏览器.我们在赞赏chrome浏览器流畅的速度时,更多的是对其chrome插件功能的赞赏.但是我们也发现了一个致命的 ...

  10. PAT 1126 Eulerian Path

    In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similar ...