其实这个题我还不会,学长给了一个代码交上去过了,据说用到了一种叫做位压缩的技术,先贴代码吧,以后看懂了再来写

#include <stdio.h>
#include <string.h> #define M 30005
#define SIZE 128
#define WORDMAX 3200
#define BIT 32 char s1[M], s2[M];
int nword;
unsigned int str[SIZE][WORDMAX];
unsigned int tmp1[WORDMAX], tmp2[WORDMAX]; void pre(int len)
{
int i, j;
memset(str, , sizeof(str));
for(i = ; i < len; i ++)
str[s1[i]][i / BIT] |= << (i % BIT);
} void cal(unsigned int *a, unsigned int *b, char ch)
{
int i, bottom = , top;
unsigned int x, y;
for(i = ; i < nword; i ++)
{
y = a[i];
x = y | str[ch][i];
top = (y >> (BIT - )) & ;
y = (y << ) | bottom;
if(x < y) top = ;
b[i] = x & ((x - y) ^ x);
bottom = top;
}
} int bitcnt(unsigned int *a)
{
int i, j, res = , t;
unsigned int b[] = {0x55555555, 0x33333333, 0x0f0f0f0f, 0x00ff00ff, 0x0000ffff}, x;
for(i = ; i < nword; i ++)
{
x = a[i];
t = ;
for(j = ; j < ; j ++, t <<= )
x = (x & b[j]) + ((x >> t) & b[j]);
res += x;
}
return res;
} void process()
{
int i, j, len1, len2;
unsigned int *a, *b, *t;
len1 = strlen(s1);
len2 = strlen(s2);
nword = (len1 + BIT - ) / BIT;
pre(len1);
memset(tmp1, , sizeof(tmp1));
a = &tmp1[];
b = &tmp2[];
for(i = ; i < len2; i ++)
{
cal(a, b, s2[i]);
t = a; a = b; b = t;
}
printf("%d\n", bitcnt(a));
} int main()
{
while(scanf("%s%s", s1, s2) != EOF)
process();
return ;
}

2253

HDU 2253 Longest Common Subsequence Again的更多相关文章

  1. 动态规划求最长公共子序列(Longest Common Subsequence, LCS)

    1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...

  2. LintCode Longest Common Subsequence

    原题链接在这里:http://www.lintcode.com/en/problem/longest-common-subsequence/ 题目: Given two strings, find t ...

  3. [UCSD白板题] Longest Common Subsequence of Three Sequences

    Problem Introduction In this problem, your goal is to compute the length of a longest common subsequ ...

  4. LCS(Longest Common Subsequence 最长公共子序列)

    最长公共子序列 英文缩写为LCS(Longest Common Subsequence).其定义是,一个序列 S ,如果分别是两个或多个已知序列的子序列,且是所有符合此条件序列中最长的,则 S 称为已 ...

  5. Longest Common Subsequence

    Given two strings, find the longest common subsequence (LCS). Your code should return the length of  ...

  6. Longest Common Subsequence & Substring & prefix

    Given two strings, find the longest common subsequence (LCS). Your code should return the length of  ...

  7. Dynamic Programming | Set 4 (Longest Common Subsequence)

    首先来看什么是最长公共子序列:给定两个序列,找到两个序列中均存在的最长公共子序列的长度.子序列需要以相关的顺序呈现,但不必连续.例如,"abc", "abg", ...

  8. Lintcode:Longest Common Subsequence 解题报告

    Longest Common Subsequence 原题链接:http://lintcode.com/zh-cn/problem/longest-common-subsequence/ Given ...

  9. UVA 10405 Longest Common Subsequence (dp + LCS)

    Problem C: Longest Common Subsequence Sequence 1: Sequence 2: Given two sequences of characters, pri ...

随机推荐

  1. Xshell调整终端显示的最大行数(缓冲区)

    1 选择会话,按顺序点击文件->属性 ,打开"会话属性"窗口 如下 在"会话属性"窗口中选择“终端” 修改缓冲区大小的值:其范围为0~2147483647 ...

  2. 【原创】JMS生产者和消费者【PTP异步接收消息】

    PTP模式下,异步接收消息需要定义一个MessageListener来监听,当生产者有消息要发送时会主动通知Listener去处理该消息,会调用监听的onMessage方法去处理. 首先看生产者(和同 ...

  3. POJ 3660 Cow Contest【传递闭包】

    解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...

  4. 关于exsi的虚拟网络

    相关术语: VM Network 默认的网络 VSwitch   (默认)标准交换机 (exsi的内核中) Port groups  (用来定义各个不同vlan) DVSwitch分布式交换机(exs ...

  5. easyui的datagrid右侧没有边框线

    做项目时,用的easyui的框架的datagrid,运行时发现右侧没有边框,其它的都有边框,使用网页的审查元素可以看到datagrid样式里的宽度没有自动减去2个像素,这些都是easyui自算的宽高, ...

  6. 我的Java历程_maven配置的心路历程

    从github上download了个maven管理的开源项目,接下来随笔下安装maven的心路历程: 异常尴尬的是import进ide之后一个红色的感叹号!震惊!google一下知道了,maven没配 ...

  7. mysql和mongodb的区别

    1.mongodb的概括 MongoDB(文档型数据库):提供可扩展的高性能数据存储 2.mongodb的功能概括 (1)基于分布式文件存储 (2)高负载情况下添加更多节点,可以保证服务器性能 (3) ...

  8. 地图底图的类型——MapView,SceneView

    MapView用于创建二维地图平面. 引用“esri/Map”,"esri/views/MapView" 具体做法并举例:var map = new Map({basemap:&q ...

  9. PHP SOAP模块的使用方法:NON-WSDL模式

    PHP SOAP扩展可以帮助我们很轻松的实现web service服务,在PHP的SOAP扩展中主要有两种操作模式:WSDL模式和NON-WSDL模式,前者通过使用WSDL文件名作为参数,并从 WSD ...

  10. java流与文件的操作 文件加密

    课后作业 1,源代码 import java.io.*; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttribu ...