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

#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. RelativeLayout.addRule()方法

    RelativeLayout.addRule()方法 通过LayoutParams的 addRule方法来额外的添加别的规则了,android.widget.RelativeLayout.Layout ...

  2. 洛谷P2766 最长不下降子序列问题 网络流_DP

    Code: #include<cstdio> #include<iostream> #include<vector> #include<algorithm&g ...

  3. oracle查询之null值转化

    函数coalesce(c1,c2,c3......cn);返回第一个不为null的值

  4. Comparator 与 Comparable

    转载自 http://www.cnblogs.com/sunflower627/p/3158042.html 1. Comparator 和 Comparable 相同的地方 他们都是java的一个接 ...

  5. NodeJS学习笔记 (2)文件系统操作-fs(ok)

    原文:https://github.com/chyingp/nodejs-learning-guide/blob/master/%E6%A8%A1%E5%9D%97/fs.md#%E9%80%9A%E ...

  6. Java将WKT格式的Geomotry转换成GeoJSON

    一.Meven添加依赖 <!-- 引入json处理包 --> <dependency> <groupId>com.alibaba</groupId> & ...

  7. 大O时间复杂度

    大O表示法指出了在最糟情况下的运行时间.比较操作数,指出了算法运行时间的增速 常见的大O运行时间 O(logn):也叫对数时间,包括二分查找 O(n):也叫线性时间,包括简单查找 O(nlogn):包 ...

  8. C#调用带结构体指针的C Dll的方法

    在C#中调用C(C++)类的DLL的时候,有时候C的接口函数包含很多参数,而且有的时候这些参数有可能是个结构体,而且有可能是结构体指针,那么在C#到底该如何安全的调用这样的DLL接口函数呢?本文将详细 ...

  9. 10个关于Android开发的实用教程

    本文为致力于Android应用的开发人员精选了几个不错的实用教程,无论是初学者还是专业开发人员都应该能够从中获益.这些教程中有不少是关于绘图和地址服务运用的,另外一些则是SDK相关的.希望对大家有所帮 ...

  10. 最强最全干货分享:Android开发书籍、教程、工具等

    最全干货分享,本文收集整理了Android开发所需的书籍.教程.工具.资讯和周刊各种资源,它们能让你在Android开发之旅的各个阶段都受益. 入门<Learning Android(中文版)& ...