当前位置:网站首页>CodeChef STMRRG String Merging (dp)
CodeChef STMRRG String Merging (dp)
2022-08-10 10:53:00 【51CTO】
Description
All submissions for this problem are available.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
For a string S, let’s define a function F(S) as the minimum number of blocks consisting of consecutive identical characters in S. In other words, F(S) is equal to 1 plus the number of valid indices i such that Si ≠ Si+1.
You are given two strings A and B with lengths N and M respectively. You should merge these two strings into one string C with length N+M. Specifically, each character of C should come either from A or B; all characters from A should be in the same relative order in C as in A and all characters from B should be in the same relative order in C as in B.
Compute the minimum possible value of F(C).
Input
The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains two space-separated integers N and M.
The second line contains a single string A with length N.
The third line contains a single string B with length M.
Output
For each test case, print a single line containing one integer — the minimum possible value of F(C).
Constraints
1 ≤ T ≤ 100
1 ≤ N, M ≤ 5,000
1 ≤ sum of N in all test cases ≤ 5,000
1 ≤ sum of M in all test cases ≤ 5,000
strings A, B consist only of lowercase English letters
Example Input
Example Output
题意
对于字符串 S,定义函数 F(S) 为:At least you can S Divide into several consecutive substrings,Makes each substring contain only the same characters.换句话说,F(S) 等于 1 加上满足 Si ≠ Si+1 的合法下标 i 的数量.
给定两个字符串 A 和 B,长度分别为 N 和 M.You need to combine the two strings into one of length N + M 的字符串 C.C Each character of is either derived from A,要么来源于 B,and derived from A The relative order of the characters should be the same as in A 中一致,来源于 B characters as well.
请求出 F(C) 最小可能的值.
思路
unique Do it directly later LCS 即可.
AC 代码
边栏推荐
猜你喜欢
随机推荐
「可扩展性」可扩展性最佳实践:来自eBay的经验教训
web项目访问引用jar内部的静态资源
database transaction
大连理工&鹏城&UAE提出用于伪装目标检测的混合尺度三重网络ZoomNet,性能SOTA!
ZZULIOJ 1116 Delete elements [delete]
JWT 实现登录认证 + Token 自动续期方案
runtime-core.esm-bundler.js?d2dd:218 Uncaught TypeError: formRef.value?.validate is not a function
「时序数据库」使用cassandra进行时间序列数据扫描
OSSCore 开源解决方案介绍
Redis6(一)——NoSQL数据库简介与Redis的安装
14 high-frequency handwritten JS interview questions and answers to consolidate your JS foundation
负载均衡原理分析与源码解读
杭电多校七 1008-Triangle Game(博弈)
database constraints
Redis (six) - transaction and lock mechanism of Redis6 (unfinished, to be supplemented)
what is bsp in rtems
CodeChef STRMRG String Merging (dp)
chart.js水平柱状图插件
Introduction to cross-end development of Taro applet
使用cpolar远程连接群晖NAS(升级固定链接2)