3301 Square words
定义square words为:
1.长度为偶数。
2.前一半等于后一半。
比如abcabc和aaaa都是square words,但是abcabcab和aaaaa都不是。
现在有一个长度为n的字符串,求至少要删掉多少个字符,使得剩下的字符串是square words。
第一行包含一个正整数n。
第二行一个长度为n的字符串,仅包含小写字母
仅包含一个整数,表示最少需要删掉的字符数
11
abaccdaabcd
3
【样例说明】
abaccdaabcd
【数据规模】
对于40%的数据,n ≤ 20;
对于100%的数据,n ≤ 500。
分类标签 Tags 点此展开
#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的更多相关文章
- code[vs]3301 Square words
暴力枚举+最长公共子序列 #include <iostream> #include <cstring> using namespace std; int dp[510][510 ...
- Square words(codevs 3301)
题目描述 Description 定义square words为: 1.长度为偶数. 2.前一半等于后一半. 比如abcabc和aaaa都是square words,但是abcabcab和aaaaa都 ...
- [LeetCode] Matchsticks to Square 火柴棍组成正方形
Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...
- [LeetCode] Valid Word Square 验证单词平方
Given a sequence of words, check whether it forms a valid word square. A sequence of words forms a v ...
- [LeetCode] Valid Perfect Square 检验完全平方数
Given a positive integer num, write a function which returns True if num is a perfect square else Fa ...
- [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 ...
- OPEN CASCADE Gauss Least Square
OPEN CASCADE Gauss Least Square eryar@163.com Abstract. The least square can be used to solve a set ...
- OpenCascade Eigenvalues and Eigenvectors of Square Matrix
OpenCascade Eigenvalues and Eigenvectors of Square Matrix eryar@163.com Abstract. OpenCascade use th ...
- 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 ...
随机推荐
- Codeforces_766_D_(并查集)
D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input ...
- 02C语言基本语法
C语言基本语法 注释 //行注释 /* 块注释*/ 标识符 标识符是用来标识变量.函数.任何其他用户自定义项目的名称:一个标识符以字母 A-Z 或 a-z 或下划线 _ 开始,后跟零个或多个字母.下划 ...
- C: 字符数组中的空去掉
#include <stdio.h> #include <string.h> int main() { char a[50] = "nearby! "; i ...
- 22万个木箱!TWaver 3D极限压榨
打开个门户网站都千呼万唤,我们还能期待网页上的3D技术会有“酣畅淋漓”.“一气呵成”的感受吗?也许现在还差点火候.但是HTML5.WebGL等技术一直在飞速的发展,可能很快你就会惊讶它的能力.现在,我 ...
- 浅析Oracle中的不等于号
前几天碰到一个关于Oracle不等于的问题,最后搜索了一下,发现下面资料,拿来跟大家分享一下,需要的朋友可以参考下 关于Oracle中的不等于号: 在Oracle中, <> != ...
- LeetCode_18 4Sum
Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums s ...
- C++STL快速入门学习
C++ STL中最基本以及最常用的类或容器无非就是以下几个: string vector set list map 下面就依次介绍一下它们,并给出一些最常见的使用方法,做到最快入门. string 首 ...
- linux whereis-查找二进制程序、代码等相关文件路径
推荐:更多Linux 文件查找和比较 命令关注:linux命令大全 whereis命令用来定位指令的二进制程序.源代码文件和man手册页等相关文件的路径. whereis命令只能用于程序名的搜索,而且 ...
- Struts2的介绍
Struts2的介绍 制作人:全心全意 Struts引用的是MVC(Model-View-Controller,模型-视图-控制器)设计理念.目前,JavaWeb应用MVC设计理念的框架有很多,如St ...
- CSC
CSC CSC Table of Contents 1. account 2. Contacts 3. <国家公派留学人员预订回国机票说明> 4. 回国手续 4.1. 申办及开具<留 ...