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 ...
随机推荐
- iframe子页面让父页面跳转 parent.location.href
if ($roleNum < 9) { echo "<script > parent.location.href='admin_login.php' </script ...
- dutacm.club_1087_Common Substrings_(KMP)_(结合此题通俗理解kmp的next数组)
1087: Common Substrings Time Limit:3000/1000 MS (Java/Others) Memory Limit:163840/131072 KB (Java/ ...
- SpringBoot项目的mybatis逆向工程
<dependencies> <!--mybatis--> <dependency> <groupId>org.mybatis.spring.boot& ...
- Xamarin.Forms android实现沉浸式
在android项目里,这样设置 using System; using Android.App; using Android.Content.PM; using Android.Runtime; u ...
- Gym - 101670B Pond Cascade(CTU Open Contest 2017 贪心,二分)
题目: The cascade of water slides has been installed in the park recently and it has to be tested. The ...
- VM 安装ubuntu16.04简易方法
在已经安装好VM10虚拟机后 首先文件—>新建虚拟机—>典型(标准) 选择稍后安装操作系统,后续要使用的是已经下载好的ubuntu16.04镜像 选择操作系统是linux ,版本是ub ...
- node-sass 安装失败
安装 npm install 时偶尔遇到报错:没有安装python或node-sass 安装失败的问题,百度之后发现是被墙了,但根据百度的方法换了淘宝镜像和用了vpn都安装失败, 原因可能是没有卸载之 ...
- [K3Cloud2.0]如何解决创建管理中心失败的问题
标题有点大,实际上,Cloud2.0产品质量还是顶呱呱的,至于在安装使用过程中出现的这个管理中心无法创建的问题,实际上是与我的网络环境有关,下面讲一下我的网络环境: 开发团队目前所在网段:10.30. ...
- Linux command2
. CentOS 想查看哪个port开了,却提示命令无效 # yum -y install net-tools 2. How to install "wget" command i ...
- Contemplation! Algebra 矩阵快速幂
Given the value of a+b and ab you will have to find the value of a n + b n Input The input file cont ...