HDU - 4323 - Magic Number
先上题目:
Magic Number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1433 Accepted Submission(s): 605
Levenshtein distance (from Wikipedia http://en.wikipedia.org/wiki/Levenshtein_distance):
In information theory and computer science, the Levenshtein distance is a string metric for measuring the amount of difference between two sequences. The term edit distance is often used to refer specifically to Levenshtein distance.
The Levenshtein distance between two strings is defined as the minimum number of edits needed to transform one string into the other, with the allowable edit operations being insertion, deletion, or substitution of a single character. It is named after Vladimir Levenshtein, who considered this distance in 1965.
For example, the Levenshtein distance between "kitten" and "sitting" is 3, since the following three edits change one into the other, and there is no way to do it with fewer than three edits:
1.kitten → sitten (substitution of 's' for 'k')
2.sitten → sittin (substitution of 'i' for 'e')
3.sittin → sitting (insertion of 'g' at the end).
In the next n lines, each line has a magic number. You can assume that each magic number is distinctive.
In the next m lines, each line has a query and a threshold. The length of each query is no more than 10 and the threshold is no more than 3.
#include <cstdio>
#include <cstring>
#define min(x,y) (x < y ? x : y)
#define unequal(x,y) (x == y ? 0 : 1)
#define MAX 12
#define INF (1<<30)
using namespace std; char s[][MAX];
char c[MAX];
int dp[MAX][MAX]; int deal(int a){
int l1,l2;
l1=strlen(s[a]+);
l2=strlen(c+);
for(int i=;i<=l1;i++) dp[i][]=i;
for(int j=;j<=l2;j++) dp[][j]=j;
for(int i=;i<=l1;i++){
for(int j=;j<=l2;j++){
dp[i][j]=INF;
}
}
for(int i=;i<=l1;i++){
for(int j=;j<=l2;j++){
dp[i][j]=min(dp[i-][j]+,dp[i][j-]+);
dp[i][j]=min(dp[i][j],dp[i-][j-]+unequal(s[a][i],c[j]));
}
}
return dp[l1][l2];
} int main()
{
int t,n,m,e,th,count;
//freopen("data.txt","r",stdin);
scanf("%d",&t);
for(int z=;z<=t;z++){
printf("Case #%d:\n",z);
scanf("%d %d",&n,&m);
for(int i=;i<n;i++){
scanf("%s",s[i]+);
}
while(m--){
scanf("%s %d",c+,&th);
count=;
for(int i=;i<n;i++){
e=deal(i);
//printf("%d ",e);
if(e<=th) count++;
}
//printf("\n");
printf("%d\n",count);
}
}
return ;
}
4323
HDU - 4323 - Magic Number的更多相关文章
- HDU 4323——Magic Number——————【dp求编辑距离】2012——MUT——3
Magic Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- HDU 4323 Magic Number(编辑距离DP)
http://acm.hdu.edu.cn/showproblem.php?pid=4323 题意: 给出n个串和m次询问,每个询问给出一个串和改变次数上限,在不超过这个上限的情况下,n个串中有多少个 ...
- Magic Number(Levenshtein distance算法)
Magic Number Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- 一个快速double转int的方法(利用magic number)
代码: int i = *reinterpret_cast<int*>(&(d += 6755399441055744.0)); 知识点: 1.reinterpret_cast&l ...
- hdu 5898 odd-even number 数位DP
传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 ...
- LVM XFS增加硬盘分区容量(resize2fs: Bad magic number in super-block while)
LVM XFS增加硬盘分区容量(resize2fs: Bad magic number -- :: 分类: Linux LVM XFS增加硬盘分区容量(resize2fs: Bad magic num ...
- hdu 2665 Kth number
划分树 /* HDU 2665 Kth number 划分树 */ #include<stdio.h> #include<iostream> #include<strin ...
- [ZOJ 3622] Magic Number
Magic Number Time Limit: 2 Seconds Memory Limit: 32768 KB A positive number y is called magic n ...
- poj magic number
Problem H Time Limit : 4000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Sub ...
随机推荐
- framebuffer的入门介绍-实现程序分析【转】
本文转载自:http://blog.csdn.net/liuzijiang1123/article/details/46972723 如想想对lcd屏进行操作(例如在lcd屏幕上画线,或者显示视频数据 ...
- hdu 1075(字典树)
What Are You Talking About Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K ...
- B1295 [SCOI2009]最长距离 最短路
就是一道最短路的裸题,直接跑spfa就行了.(spfa死了) 最后在答案处判断是否障碍物太多,然后就直接找最大值就行. (数据特别水,我错误算法60) 题干: Description windy有一块 ...
- 444D
分类 首先我们要对询问分类,如果相差log级别就第一种询问,否则第二种. 第一种直接暴力lower_bound,复杂度玄学 第二种归并,复杂度玄学 但是就是过了.感觉很容易卡. #include< ...
- Django day05 视图层之 (HttpRequest) \ (HttpResponse) \ (JsonResponse) 对象
一:视图层之HttpRequest对象 # 前台Post传过来的数据,包装到POST字典中 # request.POST # 前台浏览器窗口里携带的数据,包装到GET字典中 # request.GET ...
- DotNetCasClient加载失败问题分析
最近公司在接入整理单点登录方案的时候,选择了CAS方案,实际版本采用了4.0.当我们把服务端附属完毕,基于.NET平台Web版的客户端DotNetCasClient进行定制化修改后,在测试环境通过.然 ...
- POJ 2688 Cleaning Robot
题意: 给你一个n*m的图.你从'o'点出发,只能走路(图中的'.')不能穿墙(图中的'x'),去捡垃圾(图中的' * ')问最少走多少步能捡完所有垃圾,如有垃圾捡不了,输出-1. 思路: 有两个思路 ...
- windows phone控件
常用控件: 包括: Button控件.CheckBox控件.HyperlinkButton控件.Iamege控件.ListBox控件.PasswordBox控件.ProgressBar控件.Radio ...
- SqlSever2005 一千万条以上记录分页数据库优化经验总结【索引优化 + 代码优化】
对普通开发人员来说经常能接触到上千万条数据优化的机会也不是很多,这里还是要感谢公司提供了这样的一个环境,而且公司让我来做优化工作.当数据库中的记录不超过10万条时,很难分辨出开发人员的水平有多高,当数 ...
- 基于 CC2530 的温度采集系统(未定稿)
前言 最近在自学 Zigbee,每天的主要是任务是:看博客,看 CC2530 的 datasheet 和实践,熟悉片上的 SFR 以及控制板子. 学和做内容包括:IO.外部中断.Timer1/3/4. ...