code[vs]3301 Square words
暴力枚举+最长公共子序列
#include <iostream>
#include <cstring>
using namespace std;
int dp[510][510];
int n;
int lcs(char * a, char * b, int lena, int lenb)
{
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= lena; i++)
{
for (int j = 1; j <= lenb; j++)
{
//递推公式
if (a[i - 1] == b[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
//cout << "dp[" << lena << "][" << lenb << "]=" << dp[lena][lenb] << endl;
return (n - 2 * dp[lena][lenb]);
}
int main()
{
char str[510];
cin >> n;
int ans = n;
cin >> str;
for (int i = 1; i < n; i++)
{
ans = min(ans, lcs(str, str + i, i, n - i));
//cout << "ans = " << ans << endl;
}
cout << ans;
return 0;
}
code[vs]3301 Square words的更多相关文章
- 3301 Square words
3301 Square words 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 定义s ...
- F#之旅3 - F# PK C#:简单的求和
原文链接:https://swlaschin.gitbooks.io/fsharpforfunandprofit/content/posts/fvsc-sum-of-squares.html Comp ...
- 如何使用Android中的OpenGL ES媒体效果
引自:http://www.2cto.com/kf/201506/404366.html Android的媒体效果框架允许开发者可以很容易的应用多种令人印象深刻的视觉效果到照片或视频之上.作为这个媒体 ...
- ASCII 码对应表
Macron symbol ASCII CODE 238 : HTML entity : [ Home ][ español ] What is my IP address ? your public ...
- Bootstrap Thumbnail
Square Thumbnail with Image <!-- Square Thumbnail with Image --> <com.beardedhen.androidboo ...
- [C2P2] Andrew Ng - Machine Learning
##Linear Regression with One Variable Linear regression predicts a real-valued output based on an in ...
- 嵌入式开发笔记——调试组件SEGGER_HardFaultHandle
一.前言 在使用Cortex-M内核的MCU进行开发时,有时候会因为对内存错误访问等原因造成程序产生异常从而进入HardFaultHandler错误中断.如果程序结构比较复杂,尤其是运行了RTOS时可 ...
- Square words(codevs 3301)
题目描述 Description 定义square words为: 1.长度为偶数. 2.前一半等于后一半. 比如abcabc和aaaa都是square words,但是abcabcab和aaaaa都 ...
- OPEN CASCADE Gauss Least Square
OPEN CASCADE Gauss Least Square eryar@163.com Abstract. The least square can be used to solve a set ...
随机推荐
- Python 异常结构
http://flyheaven.blog.163.com/blog/static/7401172201193085243920/ 1.Python内建异常体系结构 The class hierarc ...
- Tornado,展示一下模板渲染
按网上一步一步走一下. 感觉模板和DJANGO的差不多,但更灵活,不限制PYTHON的使用. 前端和后端,这模板使用的规则在哪里呢? import os.path import tornado.htt ...
- IText 生成横向的doc文档
IText生成doc文档需要三个包:iTextAsian.jar,iText-rtf-2.1.4.jar,iText-2.1.4.jar 亲测无误,代码如下: import com.lowagie.t ...
- EntityFreamWork和Mvc 精品知识点
定义了DbRepository<TEntity>:IRepository<TEntity> ,SimpleDbContext继承了DbContext, UnitOfWork:I ...
- js 实现list类
js中没有list类,可以使用Array来实现list类 (function(win) { var ArrayList = function() { this.datas = []; }; var p ...
- hadoop博客
http://www.cnblogs.com/scotoma/ http://www.cnblogs.com/xia520pi/
- 7个鲜为人知却超实用的PHP函数
PHP有许多内置函数,其中大多数函数都被程序员广泛使用.但也有一些函数隐藏在角落,本文将向大家介绍7个鲜为人知,但用处非常大的函数. 没用过的程序员不妨过来看看. 1.highlight_string ...
- Extension Method[下篇]
四.Extension Method的本质 通过上面一节的介绍,我们知道了在C#中如何去定义一个Extension Method:它是定义在一个Static class中的.第一个Parameter标 ...
- pylinter could not automatically determined the path to `lint.py`
先关闭Sublime Text 1) 到官网先下载pylinter,http://www.logilab.org/project/pylint,然后解压缩,拷贝到C盘,目录为C:\pylint-1.0 ...
- Webapp meta标签解决移动缩放的问题
webapp开发初期,会碰到在pc端开发好的页面在移动端显示过大的问题,这里需要在html head中加入meta标签来控制缩放 <meta name=" viewport" ...