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 ...
随机推荐
- C++源码实现:21种常用设计模式
C++源码实现:21种常用设计模式一直以来在设计模式的学习中,都是出现java的源码,这对学习C++的极度不友好.本工程是基于C++实现21种常用的设计模式,里面包含了实例代码和示例.编写的时候在学习 ...
- 一个简单的JS日期挂历脚本
分享一个JS脚本做的日期挂历,在需要的时候可以引入你的程序. 如需单独引入这个脚本,请将它保存在一个文件中然后引入它:如这样 <script type="text/javascript ...
- Kali linux 2016.2(Rolling)之 Nessus安装及Plugins Download Fail 解决方法
最近,因科研需要,学习Nessus. Nessus是一款优秀的漏洞扫描软件,在其v6 HOME版本中在线更新漏洞插件不成功,采用离线更新,成功地更新了插件,在此将更新方法进行分享. 1.Nessus软 ...
- C#WebForm里面aspx,ajax请求后台。。。
虽然WebForm里面有那些基本控件,后台CS里面也有许许多多的控件的方法.但是不见得有些标签不需要进行后台的访问,下面介绍一下三种aspx中访问后台的方式.. 第一种:WebMethod (静态方法 ...
- Java算法——求出两个字符串的最长公共字符串
问题:有两个字符串str1和str2,求出两个字符串中最长公共字符串. 例如:“acbbsdef”和"abbsced"的最长公共字符串是“bbs” 算法思路: 1.把两个字符串分别 ...
- 易企CMS主要模板文件介绍
article.tpl 文章内容页模板 catalog.tpl 文章,产品目录页模板 category.tpl 分类页模板 comment.tpl 留言页模板 footer.tpl 页尾模板 head ...
- Android Studio Library 编译成 jar,aar
1. 导入Library ,打开Library 的build gradle 在最外面添加如下: /** AVLView 自定义的jar 包名 **/ task clearJar(type: Dele ...
- MYSQL 45道练习题
学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表(四)所示,数据如表1-2的表(一)~表(四)所示.用S ...
- 超简单:纯CSS实现的进度条
——————纯CSS实现的进度条—————— HTML: <div class="wrapper"> <div class="bar"> ...
- Glitch-free clock switch
With multi-frequency clocks being used in today’s devices, it's necessary to switch the source of a ...