HDU 2144 (最长连续公共子列 + 并查集) Evolution
我发现我一直理解错题意了,这里的子序列指的是连续子序列,怪不得我写的LCS一直WA
顺便复习一下并查集
//#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = ;
int dp[maxn][maxn], parent[maxn], len[maxn];
char DNA[maxn][maxn]; int LCS(int a, int b)
{
int ans = ;
memset(dp,,sizeof(dp));
for(int i = ; i <= len[a]; ++i)
for(int j = ; j <= len[b]; ++j)
{
if(DNA[a][i-] == DNA[b][j-])
dp[i][j] = dp[i-][j-] + ;
if(dp[i][j] > ans)
ans = dp[i][j];
}
return ans;
} int GetParent(int a)
{
return parent[a] == a ? a : parent[a] = GetParent(parent[a]);
} int main(void)
{
#ifdef LOCAL
freopen("2144in.txt", "r", stdin);
#endif int n, kase = ;
double p;
while(scanf("%d %lf", &n, &p) == )
{
for(int i = ; i < n; ++i)
{
scanf("%s", DNA[i]);
parent[i] = i;
len[i] = strlen(DNA[i]);
}
for(int i = ; i < n; ++i)
for(int j = ; j < i; ++j)
{
int pi = GetParent(i);
int pj = GetParent(j);
if(pi == pj) continue;
double x = LCS(i, j) * 100.0;
if(x/len[i]>p && x/len[j]>p)
parent[pi] = pj;
}
int ans = ;
for(int i = ; i < n; ++i)
if(parent[i] == i)
++ans;
printf("Case %d:\n%d\n", ++kase, ans);
}
return ;
}
代码君
HDU 2144 (最长连续公共子列 + 并查集) Evolution的更多相关文章
- poj3080Blue Jeans(在m个串中找到这m个串的 最长连续公共子序列)
Description The Genographic Project is a research partnership between IBM and The National Geographi ...
- hdu 3308 最长连续上升区间
LCIS Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- BUPT复试专题—最长连续等差子数列(2014软院)
题目描述 给定-个长度为N的整数数列,你需要在其中找到最长的连续子数列的长度, 并满足这个子数列是等差的.注意公差小于或等于0的情况也是允许的. 输入 第一行为数据组数T(1~100),表示测试数 ...
- 最长连续公共子序列(LCS)与最长递增公共子序列(LIS)
最长公共子序列(不连续) 实际问题中也有比较多的应用,比如,论文查重这种,就是很实际的一个使用方面. 这个应该是最常见的一种了,不再赘述,直接按照转移方程来进行: 按最普通的方式就是,直接构造二维矩阵 ...
- HDU 3081 Marriage Match II (二分图,并查集)
HDU 3081 Marriage Match II (二分图,并查集) Description Presumably, you all have known the question of stab ...
- HDU 1423 最长上升公共子序列(LCIS)
题目大意: 给定两个数字数组a[] , b[],在这两个数组中找一个最长的公共上升子序列,输出最长的长度 从别人地方copy的= = LCIS理解: (1)f[i][j] 表示 a的前i,和b串前 j ...
- HDU 4514 - 湫湫系列故事——设计风景线 - [并查集判无向图环][树形DP求树的直径]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4514 Time Limit: 6000/3000 MS (Java/Others) Memory Li ...
- hdu 1829-A Bug's LIfe(简单带权并查集)
题意:Bug有两种性别,异性之间才交往, 让你根据数据判断是否存在同性恋,输入有 t 组数据,每组数据给出bug数量n, 和关系数m, 以下m行给出相交往的一对Bug编号 a, b.只需要判断有没有, ...
- hdu 4424 & zoj 3659 Conquer a New Region (并查集 + 贪心)
Conquer a New Region Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
随机推荐
- javascript设计模式--状态模式(State)
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Google NACL 简介
Back to README Getting Started This page tells you how to install Native Client and run demos, both ...
- POJ 3696 The Luckiest number (欧拉函数,好题)
该题没思路,参考了网上各种题解.... 注意到凡是那种11111..... 22222..... 33333.....之类的序列都可用这个式子来表示:k*(10^x-1)/9进而简化:8 * (10^ ...
- POJ 1455
/* 冒泡排序n*(n-1)/2; */ #include <iostream> using namespace std; int main() { //freopen("acm ...
- C# 中Newtonsoft.Json的安装和使用
官网参考:http://json.codeplex.com/ 在程序包管理控制台,键入NuGet命令 install-package Newtonsoft.Json 安装Newtonsoft.Js ...
- jquery mobile的学习资料
磨刀不误砍柴工!想要学的快就得有好的资源.jquery mobile只是jquery的一个插件,所以相对简单易学.只要有jquery的基础就好.如果想修改东西的话,那么需要的知识就相对较多了. 书 & ...
- Codeforces Round #336 (Div. 2)C. Chain Reaction DP
C. Chain Reaction There are n beacons located at distinct positions on a number line. The i-th bea ...
- The first day of HTML
这是韩顺平老师的<轻松搞定网页设计(html.css.js)>,讲的还凑合,仅作入门.决定还是做好笔记,记录学习的过程,这是HTML的第一天. HTML(HyperText Mark-up ...
- MongoDB (九) MongoDB 投影
mongodb 投影意思是只选择必要的数据而不是选择一个文件的数据的整个.如果一个文档有5个字段,需要显示只有3个,然后选择其中只有3个字段. find() 方法 MongoDB 的find()方法, ...
- Android核心分析 之一分析方法论探讨之设计意图
为什么要研究Android,是因为它够庞大,它够复杂,他激起了我作为一个程序员的内心的渴望,渴望理解这种复杂性.我研究的对象是作为手机开发平台的Android软件系统部分,而不是Dalvik虚拟机本身 ...