hdu4323Magic Number(dp)
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)的更多相关文章
- Leetcode之动态规划(DP)专题-264. 丑数 II(Ugly Number II)
Leetcode之动态规划(DP)专题-264. 丑数 II(Ugly Number II) 编写一个程序,找出第 n 个丑数. 丑数就是只包含质因数 2, 3, 5 的正整数. 示例: 输入: n ...
- HDU 3016 Man Down (线段树+dp)
HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- LightOJ 1033 Generating Palindromes(dp)
LightOJ 1033 Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- lightOJ 1047 Neighbor House (DP)
lightOJ 1047 Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- 【HDU 5647】DZY Loves Connecting(树DP)
pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...
- 【POJ 3140】 Contestants Division(树型dp)
id=3140">[POJ 3140] Contestants Division(树型dp) Time Limit: 2000MS Memory Limit: 65536K Tot ...
- Bomb HDU - 3555 (数位DP)
Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...
- poj2342 Anniversary party (树形dp)
poj2342 Anniversary party (树形dp) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9128 ...
随机推荐
- Server Error The server encountered an error and could not complete your request. 新建站点模版失败
500 Server Error Error: Server Error The server encountered an error and could not complete your req ...
- [leetcode] 399. Evaluate Division
我是链接 看到这道题,2个点和一个权值,然后想到图,但是leetcode就是这样,没给数据范围,感觉写起来很费劲,然后就开始用图来做,添加边的时候,注意正向边和反向变,然后查询的时候,先判断2个点是否 ...
- glDatePicker-2.0 日历插件
昨天用的日历插件在绑定数据的时候出现了问题,所以今天换了这个glDatePicker-2.0 日历插件 这是我修改后的样式 默认样式是这样的. 我的代码 index.html <!doctype ...
- CSS3 animation-fill-mode 属性
现在专注于移动端开发项目,对于动画这个点是非常重要的,每当我遇到一个新的知识点,我就会和大家一起分享 animation-fill-mode :把物体动画地从一个地方移动到另一个地方,并让它停留在那里 ...
- iOS局部刷新
iOS: TableView如何刷新指定的cell 或section //一个section刷新 NSIndexSet *indexSet=[[NSIndexSet alloc]initWithInd ...
- vmware RHEL6.x 开启FTP和TELNET服务--root权限
//vmware RHEL6.x默认未安装ftp工具,需自己安装--root权限 第一部分:ftp //检查ftp是否安装 # rpm -qa | grep -i vsftpd //找到ftp的rpm ...
- PHP字符
匹配查找 strstr strpos 通常用在表单验证里面可以用到 substr 正值表达式匹配 preg_mathc(), preg)mathc_all() , preg_grep() 编码格式的转 ...
- Distributed R
R语言的分布式目前有这几个产品: (A)RHadoop:对hadoop族系的产品,其中提供了以下的组件 A.1 rhdfs 浏览读取增加修改hdfs上面的文件数据: A.2 rhbase 浏览读取增 ...
- hdu 2767 Proving Equivalences
Proving Equivalences 题意:输入一个有向图(强连通图就是定义在有向图上的),有n(1 ≤ n ≤ 20000)个节点和m(0 ≤ m ≤ 50000)条有向边:问添加几条边可使图变 ...
- An error occurred while collecting items to be installed session context was:(profile=DefaultProfile... 解决方案
遇到同样问题的小伙伴请:点击Eclipse上方工具栏中help --> Install new software... --> 看图 点击进红框的位置在打开的窗口中,将窗口右侧的Avail ...