http://acm.hdu.edu.cn/showproblem.php?pid=4323

去年的多校 编辑距离的变形 暴力居然过了 还想了好久别的方法,想得很头疼

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
using namespace std;
int dp[][],kk[],num[];
char s[][],ss[];
int main()
{
int i,j,k,n,m,t,a,b,o=,g;
scanf("%d",&t);
while(t--)
{
o++;
scanf("%d%d",&n,&m);
for(i = ; i <= n ;i++)
{
scanf("%s",s[i]);
kk[i] = strlen(s[i]);
}
for(i = ; i <= m ; i++)
{
scanf("%s %d",ss,&g);
num[i]=;
k = strlen(ss);
for(j = ; j <= n ; j++)
{
if(abs(k-kk[j])>g)
continue;
int f=;
memset(dp,,sizeof(dp));
for(a = ; a <= k ; a++)
dp[a][] = a;
for(b = ; b <= kk[j] ; b++)
dp[][b] = b;
for(a = ; a <= k ; a++)
for(b = ; b <= kk[j] ; b++)
{
if(ss[a-]==s[j][b-])
dp[a][b] = dp[a-][b-];
else
dp[a][b] = dp[a-][b-]+;
dp[a][b] = min(dp[a][b],min(dp[a][b-]+,dp[a-][b]+));
}
if(dp[k][kk[j]]<=g)
num[i]++;
}
}
printf("Case #%d:\n",o);
for(i = ; i <= m ; i++)
printf("%d\n",num[i]);
}
return ;
}

hdu4323Magic Number(dp)的更多相关文章

  1. Leetcode之动态规划(DP)专题-264. 丑数 II(Ugly Number II)

    Leetcode之动态规划(DP)专题-264. 丑数 II(Ugly Number II) 编写一个程序,找出第 n 个丑数. 丑数就是只包含质因数 2, 3, 5 的正整数. 示例: 输入: n ...

  2. HDU 3016 Man Down (线段树+dp)

    HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  3. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  4. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

  5. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  6. 【HDU 5647】DZY Loves Connecting(树DP)

    pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...

  7. 【POJ 3140】 Contestants Division(树型dp)

    id=3140">[POJ 3140] Contestants Division(树型dp) Time Limit: 2000MS   Memory Limit: 65536K Tot ...

  8. Bomb HDU - 3555 (数位DP)

    Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...

  9. poj2342 Anniversary party (树形dp)

    poj2342 Anniversary party (树形dp) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9128   ...

随机推荐

  1. 2.1 JavaScript应用开发实践指南

    创建交互层 循环 示例代码如下: var people = family, peopleCount = items.length, i; if(peopleCount>0){ for(i=0; ...

  2. Spring框架中的单例Beans是线程安全的么?

    Spring框架并没有对单例bean进行任何多线程的封装处理.关于单例bean的线程安全和并发问题需要开发者自行去搞定.但实际上,大部分的Spring bean并没有可变的状态(比如Serview类和 ...

  3. Linux内核Radix Tree(三):API介绍

    1.     单值查找radix_tree_lookup 函数radix_tree_lookup执行查找操作,查找方法是:从叶子到树顶,通过数组索引键值值查看数组元素的方法,一层层地查找slot.其列 ...

  4. JSON字符串转换为JSON对象

    一.JSON字符串转换为JSON对象 A:eval函数 eval函数可以直接将本质符合或者近似符合JSON格式的字符串转换为JSON对象,使用方式如: eval('(' + str + ')'); / ...

  5. MySQL的EXPLAIN命令详解(转)

    explain显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. 使用方法,在select语句前加上explain就可以了: 如: expla ...

  6. python初准备:安装easy_install和pip

    安装easy_install wget http://peak.telecommunity.com/dist/ez_setup.py python ez_setup.py 安装pip wget htt ...

  7. eclipse中使用jython

    通过maven配置加载这个包,目前比较稳定的是python2.7的,见 <dependency> <groupId>org.python</groupId> < ...

  8. ctrl+c关闭多线程python程序

    项目中经常需要用到多线程,如果一个python程序用了多线程,当子线程没有结束时,用ctrl+c是关闭不了主线程的,这时候就只能用kill命令杀掉,这样会很麻烦. 所以探讨了下怎么ctrl+C关闭多线 ...

  9. Project not selected to build for this solution configuration.

    Project not selected to build for this solution configuration.   When you upgrade your older solutio ...

  10. 中国.net域名网站的“前世今生”,那些年的光辉

    1987年9月的一天,中国的第一封电子邮件成功发出,邮件的内容大致是“跨越长城,走向世界”,在当时,没有人会想到十年后中国的互联网开始萌芽,并发展成今天的繁荣.1994年,“巴黎统筹委员会”的解散消除 ...