当前位置:网站首页>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 代码
边栏推荐
猜你喜欢

JS高级 之 使用 Iterator - Generator
![[Azure Cloud] What is the difference between a service endpoint and a private link?point of view (1)](/img/f6/561a5ff4e518d423cc13a58dcc4383.png)
[Azure Cloud] What is the difference between a service endpoint and a private link?point of view (1)

MongoDB database notes

「敏捷建模」纪律:敏捷设计理念

【STL】位图的介绍使用以及代码的模拟实现

14 high-frequency handwritten JS interview questions and answers to consolidate your JS foundation

使用cpolar远程连接群晖NAS(升级固定链接2)

商城限时秒杀功能系统

兼容移动和PC的loading加载和toast消息插件

跨公网环境,路由策略,进行设备的访问
随机推荐
ZZULIOJ 1124: Merge two sorted arrays
chart.js horizontal column chart plugin
态势丨黑客侵扰加剧,靶场为网络安全架设“防御盾”
C语言题解:倒置字符串
网络安全笔记5——数字签名
JWT 实现登录认证 + Token 自动续期方案
mysql5.7安装部署-yum安装
这些年我开源的几个小项目
「数据战略」结果驱动的企业数据策略:组织和治理
自动化测试及Selenium
面试官:项目中 Dao、Service、Controller、Util、Model 怎么划分的?
14 high-frequency handwritten JS interview questions and answers to consolidate your JS foundation
2022.8.7-----leetcode.636
"Time Series Database" uses cassandra to scan time series data
gin-gonic/gin使用详解
用.bat文件做Airtest脚本的多设备批量运行
首次入选OSDI顶会!腾讯提出超大规模推荐系统的模型低延时更新方案
WebView2 通过 PuppeteerSharp 实现爬取 王者 壁纸 (案例版)
Thrift -- 跨语言RPC 框架
dedecms supports one-click upload of Word content