51nod 1732 LCS变形
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1732



现给定字符串长度n,与字符串S。接下来是整数q,代表接下来有q次查询。
下面q行有两个整数ai, bi。代表查询特质为ai与bi的用户的匹配度。 1 <= n <= 1000
1 <= q <= 10^6 输入数据全部合法。
每一行输出一个用户匹配度整数。
12
loveornolove
5
3 7
0 0
9 1
3 1
9 5
0
12
3
0
0
f[i][j]表示从i开始和从j开始的字符串的最长公共前缀,显然 f[i][j]={ f[i+1][j+1]+1|if(s[i]==s[j] , 0 }
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL mod=1e9+;
char s[];
int f[][];
int main()
{
int len,n,q,i,j,k;
while(scanf("%d",&len)==){
int a,b;
scanf("%s",s+);
scanf("%d",&q);
memset(f,,sizeof(f));
for(i=len;i>=;--i)
{
for(j=len;j>=;--j)
{
if(s[i]==s[j]) f[i][j]=f[i+][j+]+;
else f[i][j]=;
}
}
while(q--){
scanf("%d%d",&a,&b);
a++;
b++;
printf("%d\n",f[a][b]);
}
}
return ;
}
51nod 1732 LCS变形的更多相关文章
- poj 1080 (LCS变形)
Human Gene Functions 题意: LCS: 设dp[i][j]为前i,j的最长公共序列长度: dp[i][j] = dp[i-1][j-1]+1;(a[i] == b[j]) dp[i ...
- POJ 1080( LCS变形)
题目链接: http://poj.org/problem?id=1080 Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K ...
- UVA-1625-Color Length(DP LCS变形)
Color Length(UVA-1625)(DP LCS变形) 题目大意 输入两个长度分别为n,m(<5000)的颜色序列.要求按顺序合成同一个序列,即每次可以把一个序列开头的颜色放到新序列的 ...
- 51Nod - 1092 回文字符串(添加删除字符LCS变形)
回文字符串 回文串是指aba.abba.cccbccc.aaaa这种左右对称的字符串.每个字符串都可以通过向中间添加一些字符,使之变为回文字符串. 例如:abbc 添加2个字符可以变为 acbbca, ...
- Advanced Fruits(HDU 1503 LCS变形)
Advanced Fruits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- poj1080--Human Gene Functions(dp:LCS变形)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17206 Accepted: ...
- HDU 5791 Two ——(LCS变形)
感觉就是最长公共子序列的一个变形(虽然我也没做过LCS啦= =). 转移方程见代码吧.这里有一个要说的地方,如果a[i] == a[j]的时候,为什么不需要像不等于的时候那样减去一个dp[i-1][j ...
- uva 10723 Cyborg Genes(LCS变形)
题目:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=107450#problem/C 题意:输入两个字符串,找一个最短的串,使得输入的两个 ...
- Combine String---hdu5727 &&& Zipper(LCS变形)
题目链接:http://poj.org/problem?id=2192 http://acm.split.hdu.edu.cn/showproblem.php?pid=5707 http://acm. ...
随机推荐
- (4.6)sql server索引缺失提示
SQLSERVER如何查看索引缺失 sql server索引缺失提示 当大家发现数据库查询性能很慢的时候,大家都会想到加索引来优化数据库查询性能, 但是面对一个复杂的SQL语句,找到一个优化的索引组合 ...
- Oracle 11g Enhancements in AWR Baselines
Enhancements in AWR Baselines A baseline is any set of snapshots taken over a period of time. The sn ...
- Python基础-set集合
1.集合的创建 s = set('fansik and fanjinbao') print(s) 打印结果(去掉了重复的字符):{'k', 'd', 'f', 'n', ' ', 'j', 'i', ...
- java.lang.IllegalStateException: availableProcessors is already set to [4], rejecting [4]
Links: 1.Getting availableProcessors is already set to [1], rejecting [1] IllegalStateException exce ...
- c#中使用NetCDF存储二维数据的读写操作简单应用
[DllImport( [DllImport( [DllImport( ...
- 服务中的 API 网关(API Gateway)
我们知道在微服务架构风格中,一个大应用被拆分成为了多个小的服务系统提供出来,这些小的系统他们可以自成体系,也就是说这些小系统可以拥有自己的数据库,框架甚至语言等,这些小系统通常以提供 Rest Api ...
- shell中的$()、${}、$(())、(())
$( ) 与 ` ` (反引号)在 bash shell 中,$( ) 与 ` ` (反引号) 都是用来做命令替换用(command substitution)的. 所谓的命令替换与我们第五章学过的变 ...
- nodejs 各种插件
__dirname:全局变量,存储的是文件所在的文件目录 __filename:全局变量,存储的是文件名 代码:dirname.jsconsole.log(__dirname); 运行node dir ...
- 外网IP地址API
新浪的IP地址查询接口:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js 新浪多地域测试方法:http://int.dpool. ...
- 类锁、对象锁、互斥锁与synchronized
本文总结自: https://blog.csdn.net/luckey_zh/article/details/53815694 互斥锁: 若对象有互斥锁,则在任一时刻,只能有一个线程访问对象.类锁.对 ...