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 ...
随机推荐
- 如何利用CSS中的ime-mode用来控制页面上文本框中的全角/半角输入
css 之 ime-mode语法:ime-mode : auto | active | inactive | disabled取值:auto : 默认值.不影响ime的状态.与不指定 ime-mode ...
- 再谈布局之 UIStackView
UIStackView 是 iOS9 新增的一个布局技术.熟练掌握相当节省布局时间. UIStackView 是 UIView 的子类,是用来约束子控件的一个控件.但他的作用仅限于此,他不能被渲染(即 ...
- CAD得到指定条件的实体
主要用到函数说明: IMxDrawSelectionSet::Select2 构造选择集.详细说明如下: 参数 说明 [in] MCAD_McSelect Mode 构造选择集方式 [in] VARI ...
- python多进程和多线程编程
17 多线程和多进程并发 The modules described in this chapter provide support for concurrent execution of code. ...
- 行内块+calc+margin 三列布局
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'.
在连接数据库时,使用了最新版本的mysql-Connector,所以导致老版本的“com.mysql.jdbc.Drive”不可行,要改为“com.mysql.cj.jdbc.Driver”
- linux怎么查看已装好硬件驱动
linux系统中的设备驱动是否安装好一般检查几个方面:1.系统日志.嵌入式系统多是直接dmesg一下,看有没有设备关键字相关的出错信息(通用系统可检查/var/log/messages文件).2.已加 ...
- Platform 获取主机系统信息
该模块用来访问平台相关属性. 常见属性和方法 1. import platform(pip install platform) 2.获取操作系统名称及版本号 def get_platform(): ...
- PHP上传文件到七牛(Qiniu)
上传文件到七牛最简单的方式就是使用七牛官方最新的SDK 安装PHP SDK composer require qiniu/php-sdk 上传文件到七牛 use Qiniu\Auth; use Qin ...
- 版本优化-test
版本优化 标签(空格分隔): 测试 需求经手人太多,直接提bug,开发不乐意,跟Leader确认不靠谱,跟PM确认,不熟悉流程,跟第三方PM确认靠谱了,结果被开发三言两语,变成了不改bug 而改需求 ...