字符串DP

SPI协议详解(图文并茂+超详细) 先说串口 因为之前写过一篇UART,通用串行异步通讯协议,UART的相关资料 因为UART没有时钟信号,无法控制何时发送数据,也无法保证双发按照完全相同的速度接收数据。因此,双方以不同的速度进行数据接收和发送,就会出现问题。 如果要解决这个问题,UART为每个字节添加额外的起始位和停止位,以帮助接收器在数据到达时进行同步; 双方还必须事先就传输速度达成共识(设置相同的波特率,例如每秒9600位)。 传输速率如果有微小差异不是问题,因为接收器会在每个字节的开头重新同步。相应的协议如下图所示; 如果您注意到 阅读详情

  这几天在做DP,总结一下,先是字符串这一类的。

  最简单的就是给你两个字符串a和b,让你求最长公共子序列(LCS)。用dp[i][j]作为第一个字符串匹配到i位置和第二个字符串匹配到j位置时的最长公共子序列,所以如果a[i]==b[j],dp[i][j]=dp[i-1][j-1]+1,否则dp[i][j]=max(dp[i-1][j],dp[i][j-1])。

  之后一些题就和是这个的变形了,但是思路还是差不多的。

  有一种是给你一个字符串,问最少在这个字符串中增加几个字母能使这个它变成回文串,比如Ab3bd至少要加2个变成dAb3bAd或Adb3bdA。这个其实和上面LCS是一样的,只要把a反着存一遍到b,设串长度为N,求出dp[N][N],然后用N-dp[N][N]结果(也可以不复制,直接倒着做,不过没这个简单)。


C - The Cow Lexicon
Time Limit:2000MS    Memory Limit:65536KB    64bit IO Format:%I64d & %I64u

Description

Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words, each containing no more 25 of the characters 'a'..'z'. Their cowmunication system, based on mooing, is not very accurate; sometimes they hear words that do not make any sense. For instance, Bessie once received a message that said "browndcodw". As it turns out, the intended message was "browncow" and the two letter "d"s were noise from other parts of the barnyard.

The cows want you to help them decipher a received message (also containing only characters in the range 'a'..'z') of length L (2 ≤ L ≤ 300) characters that is a bit garbled. In particular, they know that the message has some extra letters, and they want you to determine the smallest number of letters that must be removed to make the message a sequence of words from the dictionary.

Input

Line 1: Two space-separated integers, respectively: W and L
Line 2: L characters (followed by a newline, of course): the received message
Lines 3.. W+2: The cows' dictionary, one word per line

Output

Line 1: a single integer that is the smallest number of characters that need to be removed to make the message a sequence of dictionary words.

Sample Input

6 10
browndcodw
cow
milk
white
black
brown
farmer

Sample Output

2

  这个是问最少删掉多少个字母能让剩下的字母能组成下面的单词。dp[i]代表从第1个到第i个字母需要删掉的最小字母。设串长度为N,做法是i从1循环到N,每次把下面的单词都尝试一遍,得到最优的dp[i]。

代码:

#include<stdio.h>
#include<string.h>
char a[610];
char s[610][35];
int dp[310];
int min(int a,int b)
{
    return a<b?a:b;
}
int main()
{
    int W,L;
    while(scanf("%d%d",&W,&L)!=EOF)
    {
        scanf("%s",a);
        int i,j,k;
        for(i=0; i<W; i++) scanf("%s",s[i]);
        dp[0]=0;
        for(i=1; i<=L; i++) dp[i]=99999;
        for(i=1; i<=L; i++)
        {
            for(j=0; j<W; j++)
            {
                int find=0,l;
                int p2=strlen(s[j])-1,p1=i-1;
                if(s[j][p2]==a[p1]&&p2<=p1)  //看前面的所有字母能否包含这个单词
                    while(p1>=0)
                    {
                        if(s[j][p2]==a[p1])
                        {
                            p1--;
                            p2--;
                        }
                        else p1--;
                        if(p2==-1)
                        {
                            find=1;
                            l=i-p1-1;
                            break;
                        }
                    }
                if(find) dp[i]=min(dp[i],dp[i-l]+l-strlen(s[j]));
                dp[i]=min(dp[i],dp[i-1]+1);
            }
        }
        printf("%d\n",dp[L]);
    }
}

H - Human Gene Functions
Time Limit:1000MS    Memory Limit:10000KB    64bit IO Format:%I64d & %I64u

Description

It is well known that a human gene can be considered as a sequence, consisting of four nucleotides, which are simply denoted by four letters, A, C, G, and T. Biologists have been interested in identifying human genes and determining their functions, because these can be used to diagnose human diseases and to design new drugs for them.

A human gene can be identified through a series of time-consuming biological experiments, often with the help of computer programs. Once a sequence of a gene is obtained, the next job is to determine its function.
One of the methods for biologists to use in determining the function of a new gene sequence that they have just identified is to search a database with the new gene as a query. The database to be searched stores many gene sequences and their functions – many researchers have been submitting their genes and functions to the database and the database is freely accessible through the Internet.

A database search will return a list of gene sequences from the database that are similar to the query gene.
Biologists assume that sequence similarity often implies functional similarity. So, the function of the new gene might be one of the functions that the genes from the list have. To exactly determine which one is the right one another series of biological experiments will be needed.

Your job is to make a program that compares two genes and determines their similarity as explained below. Your program may be used as a part of the database search if you can provide an efficient one.
Given two genes AGTGATG and GTTAG, how similar are they? One of the methods to measure the similarity
of two genes is called alignment. In an alignment, spaces are inserted, if necessary, in appropriate positions of
the genes to make them equally long and score the resulting genes according to a scoring matrix.

For example, one space is inserted into AGTGATG to result in AGTGAT-G, and three spaces are inserted into GTTAG to result in –GT--TAG. A space is denoted by a minus sign (-). The two genes are now of equal
length. These two strings are aligned:

AGTGAT-G
-GT--TAG

In this alignment, there are four matches, namely, G in the second position, T in the third, T in the sixth, and G in the eighth. Each pair of aligned characters is assigned a score according to the following scoring matrix.

denotes that a space-space match is not allowed. The score of the alignment above is (-3)+5+5+(-2)+(-3)+5+(-3)+5=9.

Of course, many other alignments are possible. One is shown below (a different number of spaces are inserted into different positions):

AGTGATG
-GTTA-G

This alignment gives a score of (-3)+5+5+(-2)+5+(-1) +5=14. So, this one is better than the previous one. As a matter of fact, this one is optimal since no other alignment can have a higher score. So, it is said that the
similarity of the two genes is 14.

Input

The input consists of T test cases. The number of test cases ) (T is given in the first line of the input file. Each test case consists of two lines: each line contains an integer, the length of a gene, followed by a gene sequence. The length of each gene sequence is at least one and does not exceed 100.

Output

The output should print the similarity of each test case, one per line.

Sample Input

2 
7 AGTGATG 
5 GTTAG 
7 AGCTATT 
9 AGCTTTAAA 

Sample Output

14
21 

  这个也是,一开始觉得好难,其实也就是那样。状态转移方程

dp[i][j]=max(dp[i-1][j-1]+p[a[i-1]][b[j-1]],dp[i][j-1]+p['-'][b[j-1]],dp[i-1][j]+p[a[i-1]]['-']);
代码:

#include<stdio.h>
#include<string.h>
char a[110],b[110];
int dp[110][110],p[120][120];
int max(int a,int b,int c)
{
    if(a>=b&&a>=c) return a;
    if(b>=a&&b>=c) return b;
    if(c>=a&&c>=b) return c;
}
int main()
{
    int T,N,M;
    scanf("%d",&T);
    memset(p,0,sizeof(p));
    p['A']['A']=5;
    p['A']['C']=p['C']['A']=-1;
    p['A']['G']=p['G']['A']=-2;
    p['A']['T']=p['T']['A']=-1;
    p['A']['-']=p['-']['A']=-3;
    p['C']['C']=5;
    p['C']['G']=p['G']['C']=-3;
    p['C']['T']=p['T']['C']=-2;
    p['C']['-']=p['-']['C']=-4;
    p['G']['G']=5;
    p['G']['T']=p['T']['G']=-2;
    p['G']['-']=p['-']['G']=-2;
    p['T']['T']=5;
    p['T']['-']=p['-']['T']=-1;
    while(T--)
    {
        scanf("%d%s%d%s",&N,a,&M,b);
        int i,j,m;
        dp[0][0]=0;
        for(i=1; i<=N; i++) dp[i][0]=dp[i-1][0]+p[a[i-1]]['-'];
        for(i=1; i<=M; i++) dp[0][i]=dp[0][i-1]+p['-'][b[i-1]];
        for(i=1; i<=N; i++)
            for(j=1; j<=M; j++)
                dp[i][j]=max(dp[i-1][j-1]+p[a[i-1]][b[j-1]],dp[i][j-1]+p['-'][b[j-1]],dp[i-1][j]+p[a[i-1]]['-']);
        printf("%d\n",dp[N][M]);

    }
}

K - Magic Number
Time Limit:1000MS    Memory Limit:65536KB    64bit IO Format:%I64d & %I64u

Description

There are many magic numbers whose lengths are less than 10. Given some queries, each contains a single number, if the Levenshtein distance (see below) between the number in the query and a magic number is no more than a threshold, we call the magic number is the lucky number for that query. Could you find out how many luck numbers are there for each query?

Levenshtein distance (from Wikipedia http://en.wikipedia.org/wiki/Levenshtein_distance):
In information theory and computer science, the Levenshtein distance is a string metric for measuring the amount of difference between two sequences. The term edit distance is often used to refer specifically to Levenshtein distance.
The Levenshtein distance between two strings is defined as the minimum number of edits needed to transform one string into the other, with the allowable edit operations being insertion, deletion, or substitution of a single character. It is named after Vladimir Levenshtein, who considered this distance in 1965.
For example, the Levenshtein distance between "kitten" and "sitting" is 3, since the following three edits change one into the other, and there is no way to do it with fewer than three edits:
1.kitten → sitten (substitution of 's' for 'k')
2.sitten → sittin (substitution of 'i' for 'e')
3.sittin → sitting (insertion of 'g' at the end).
 

Input

There are several test cases. The first line contains a single number T shows that there are T cases. For each test case, there are 2 numbers in the first line: n (n <= 1500) m (m <= 1000) where n is the number of magic numbers and m is the number of queries.
In the next n lines, each line has a magic number. You can assume that each magic number is distinctive.
In the next m lines, each line has a query and a threshold. The length of each query is no more than 10 and the threshold is no more than 3.
 

Output

For each test case, the first line is "Case #id:", where id is the case number. Then output m lines. For each line, there is a number shows the answer of the corresponding query.
 

Sample Input

    
1 5 2 656 67 9313 1178 38 87 1 9509 1
 

Sample Output

  
Case #1: 1 0

  问的是下面那些数能在给定的次数范围内通过增加、删除、改变字母变成上面的数字的个数。思路依然是一样的,用dp[i][j]存a到第i个字符和b到第j个字符时的结果,如果a[i-1]==b[j-1],那么

dp[i][j]=min(dp[i-1][j-1],dp[i][j])
然后对于所有情况有(前2个是删除、增加,第3个是修改)

dp[i][j]=min(dp[i-1][j]+1,dp[i][j-1]+1,dp[i-1][j-1]+1);
代码:

#include<stdio.h>
#include<math.h>
#include<string.h>
int N=0;
int min(int a,int b)
{
    return a<b?a:b;
}
char a[1510][21],b[21];
int dp[21][21];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        printf("Case #%d:\n",++N);
        int n,m,i,j,k,t;
        scanf("%d%d",&n,&m);
        for(i=0; i<n; i++) scanf("%s",a[i]);
        while(m--)
        {
            int ans=0,l1,l2;
            scanf("%s%d",b,&t);
            for(k=0; k<n; k++)
            {
                l1=strlen(a[k]);
                l2=strlen(b);
                if(abs(l1-l2)>t) continue;
                for(i=0; i<=l2; i++) dp[i][0]=i;
                for(i=0; i<=l1; i++) dp[0][i]=i;
                for(i=1; i<=l2; i++)
                    for(j=1; j<=l1; j++)
                    {
                        dp[i][j]=min(dp[i-1][j]+1,dp[i][j-1]+1);
                        if(a[k][j-1]==b[i-1]) dp[i][j]=min(dp[i-1][j-1],dp[i][j]);
                        else dp[i][j]=min(dp[i-1][j-1]+1,dp[i][j]);
                    }
                if(dp[l2][l1]<=t) ans++;
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}

  总之,字符串这类的DP经常出现几种情况。

  1.两层循环,dp[i][j]代表一个字符串匹配到i位置另一个字符串匹配到j位置的结果,答案是dp[N][N]。

  2.dp[i]表示从1到i的结果,答案是dp[N]。

  3.dp[i][j]表示一个字符串位置i到位置j的结果,答案是dp[1][N]。

QCC304x系列开发教程(基础篇)之2.1-QCC3040之开发环境搭建 一、安装MDE 1.解压qualcomm_mde.win.2.4_installer_2.4.1.4压缩包,安装MDE_WIN_2.4.1.4_x64.exe,路径自定义 点击NEXT, 安装完成后,点击Finish. 完成安装后,桌面生成快捷方式 阅读详情

相关推荐

有限元缺陷:剪切锁死

有限元缺陷:剪切锁死

wsxww11的博客 5201

字符串DP总结

字符串DP题型复盘一、回文字符串多维度变形1.求字符串中最长回文`子序列`长度1.最长回文子序列---区间DP题目链接2.求字符串中最长回文`子串`长度1.最长回文子串---区间DP题目链接2.小A的回文串---区间DP题目链接3.无权值回文字符串最值问题1.Palindrome---LCS优化题目链接4、有权值回文字符串最值问题1.Cheapest Palindrome---区间dp题目链接5.合并回文子串1.合并回文子串---区间DP题目链接二、从原串中找子序列1.不同的子序列---DP题目链接2.Nu

ZZU_LGY 1533

网络安全学习路线是怎样的?

为什么要学习安全? 近几年网络安全事件层出不穷,相信大家哪怕没遇到过,但也听过不少了吧。如服务器遭受入侵被黑,用户帐号被盗;被钓鱼、勒索病毒等,这些一旦发生,对企业而言都是不小的打击。因此,网络安全不容忽视,同时随着时代的不断发展,公司对于运维及网络工程师要求也越来越严格。未来越来越吃香的一定是技能方向广的复合型人才。网络安全可以说是一条非常好的发展道路。 今年两会期间,全国政协委员,360集团创始人、董事长周鸿祎提交了关于网络安全行业特殊人才的提案,为广大白帽子人员争取更好...

网安技术分享 8733

字符串dp系列

647.回文子串 给定一个字符串,你的任务是计算这个字符串中有多少个回文子串。 具有不同开始位置或结束位置的子串,即使是由相同的字符组成,也会被计为是不同的子串。 示例1: 输入:"abc" 输出:3 解释:三个回文子串:"a","b","c". 示例2: 输入:"aaa" 输出:6 说明:6个回文子串:"a","a","a","aa","aa","aaa". 1.暴力,生成所有子串,一个个判断 2.dp[j][i]表示从j到i是否为回文串,如果s[j]=.

北歌的博客 1707

基于继电器与三极管的自动水泵控制器DIY:从电路原理到PCB制作实战

继电器作为一种利用电磁原理实现电路通断控制的电气开关,其核心价值在于通过小电流信号控制大电流负载,实现强弱电之间的安全隔离。在自动化控制领域,继电器常与三极管等半导体器件配合,构成驱动电路,将微弱的传感器信号放大,从而可靠地控制电机、水泵等执行机构。这种组合技术广泛应用于工业控制、智能家居及各类电子DIY项目中,例如实现水箱水位的自动检测与控制。本文将以一个典型的自动水泵控制器项目为例,深入剖析如何利用继电器与三极管搭建水位检测与驱动电路,并详细讲解从电路设计、PCB自制(热转印法)到系统调试的完整工程实践

weixin_31774841的博客 367

手把手教你学Simulink--基于车联网与智能交通系统的场景实例:基于车联网(V2X)的实时路况信息共享与处理

《基于Simulink的车联网(V2X)实时路况共享系统仿真》摘要:本文详细介绍使用Simulink构建V2X智能交通系统的完整方法。系统包含交通路网建模、V2X通信实现(支持DSRC/C-V2X标准)、多源路况信息融合、动态路径规划等核心模块。通过对比实验,验证V2X可使平均车速提升52%,行程时间缩短34%,显著提升交通效率。文章还探讨了AI预测调度、车辆编队等高级应用,为智慧交通系统开发提供实用参考。所需工具包括Simulink、SimEvents及无线通信工具箱等。

MHD0815的博客 745

DP:回文串模型

有关回文子串的复杂问题,大多可以用dp去解决

weixin_51142926的博客 3810

21天教你学会PCIe专栏(17)--多功能设备

1.1 定义多功能PCIe设备:多功能PCIe设备是指在一个物理设备中集成了多种功能的设备。这些功能可以通过不同的PCIe功能(Function)来实现,每个功能可以独立配置和管理。1.2 优点资源利用率:通过集成多种功能,减少物理设备的数量,提高资源利用率。成本效益:减少硬件成本和功耗,提高系统的经济性。灵活性:用户可以根据需要启用或禁用不同的功能,提高系统的灵活性。可扩展性:通过增加新的功能,扩展设备的功能,提高系统的可扩展性。1.3 应用场景网络设备。

xiaoheshang_123的博客 536

字符串DP问题

文章目录前言例题1例题2 前言 对于一些字符串问题,比如求一串字符中最长的回文串,或者是一些回文串的变种问题,我们一般可以使用一个二维的DP数组来保存计算的结果,从而减少计算量,下面我用两个例题来解释 例题1 例题的链接 例题2 516. Longest Palindromic Subsequence 给定一个字符串s,找出s中最长的回文子序列的长度。 子序列是一个序列,可以通过删除部分或不删除元素而从另一个序列派生,而不改变其余元素的顺序。 我们可以将一个字符串的任意字串用一个二维DP数组来表示,比如s[

NP_hard的博客 451

Opencv项目实战:09 物体尺寸测量

《Opencv项目实战:09 物体尺寸测量》本项目主要是运用了之前扫描文档的思想,以A4纸为背景,检测其中区域的物体长和宽。我的摄像头无法固定,所以是手持的,且由于我在寝室里面是真的没有找到合适的测量物体以及背景色(全是米色或原木色的)。所以效果有所欠缺,但经过ps修改的图片,检测的效果还是很不错的。

m0_62919535的博客 1万+

置顶必读(2) |《YOLOv8实战:从入门到深度优化》总目录导航 & 学习路线指南(持续更新中)

🏆 本文收录于 《YOLOv8实战:从入门到深度优化》 专栏。该专栏系统复现并梳理全网各类 YOLOv8 改进与实战案例(当前已覆盖分类 / 检测 / 分割 / 追踪 / 关键点 / OBB 检测等方向),坚持持续更新 + 深度解析,质量分长期稳定在 97 分以上,可视为当前市面上 覆盖较全、更新较快、实战导向极强 的 YOLO 改进系列内容之一。

**My Coding Family** 28万+

DP--字符串变换

给定两个字符串,已知可以使用三种方式进行变换 1. 插入一个字符 2. 删除一个字符 3. 更改一个字符 请设计一个算法,找到两个字符串之间的经历几次最小变换,可以字符串1转换成字符串2 输入描述: 输入两个字符串,字符串的长度<=1000 输出描述: 最小变换次数 示例1 输入 hello helle 输出 1 #include <iostre...

qq_35747066的博客 631

Angular项目内存优化策略

最近,我购买了一台新的设备,期望能够显著提升工作效率,特别是在运行Angular项目时。然而,尽管设备配置先进,我仍然遇到了内存不足的错误。今天,我将分享如何解决这一问题,以及一些在Angular项目中优化内存使用的方法。

m0_74337424的博客 180

数位dp,找到所有最好字符串

dp实际上就是填表的过程(后面的数据依赖前面的数据) 数位dp也是如此,它的本质就是dfs,只不过在深度遍历的时候记录每种情况的数值,下次遇到这种情况时可以直接使用该种情况记录过的值,从而省去了重复的递归达到优化的过程。 这里介绍两种例题: 1.462,就是给定一个上界n和一个下界m要我们求出不含4,且没有连续的62的数的个数。 这里情况的定义为:该位为6和不为6这两种情况(只能在不为上界/下届时...

knswd的博客 305

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

字符串——dp

Reverse and Compare 这道题看起来像回文串的题,但却不是。。。。 我们考虑 si和sjs_i和s_jsi​和sj​换后本质不同, 则si与sjs_i与s_jsi​与sj​一定不是回文串,但为了不重复,我们找到第一个不同的交换,后面如果出现相同的就是同种方案 dp[i]表示前i个中字符串的方案数dp[i]表示前i个中字符串的方案数dp[i]表示前i个中字符串的方案数 我们扫描前面有...

LELElele01的博客 284

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

DP字符串类型题汇总

DP字符串类型题汇总 最长公共子串(LCS) //输出A和B最长公共子串的长度, 并打印结果 #include <bits/stdc++.h> using namespace std; const int maxn = 1005; int d[maxn][maxn]; char a[maxn], b[maxn]; int la, lb; int main() { #ifdef LO...

→↗允↘的博客 1999

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

【DP入门】回文字符串

题目来自nyist第37题,如下: 描述 所谓回文字符串,就是一个字符串,从左到右读和从右到左读是完全一样的,比如"aba"。当然,我们给你的问题不会再简单到判断一个字符串是不是回文字符串。现在要求你,给你一个字符串,可在任意位置添加字符,最少再添加几个字符,可以使这个字符串成为回文字符串。 输入 第一行给出整数N(0 接下来的N行,每行一个字符串,每个字符串长度不超过1000. 输出

github_36652477的博客 1300

交错字符串(dp)

题目:https://leetcode-cn.com/problems/interleaving-string/ class Solution { public: bool isInterleave(string s1, string s2, string s3) { /* *给定三个字符串 s1, s2, s3, 验证 s3 是否是由 *...

weixin_43918473的博客 180

#216-[DP]字符串距离

Description 给出两个由小写字母组成的字符串X和Y,我们需要算出两个字符串的距离,定义如下: 1)我们可以在字符串的头、尾、中间插入若干空格,组成一个新的扩展串 2)对X扩展成扩展串X1,对Y扩展成扩展串Y1,并且令X1和Y1具有相同的长度 3)定义X1、Y1的距离为每个对应的字符的距离之和,其中两个空格的距离为0,两个非空格字符的距离为其ASCII码之差的绝对...

2017gdgzoi999的博客 466

字符串dp - WOJ#1223 子串

传送门 Analysis 首先这个名字“字符串dp”就是我乱取的……反正在字符串上搞嘛 第二次做,在知道这是dp的情况下,依旧没有分析出来。。在大致瞥了一眼定义后,仍旧没有转移对。菜是十大原罪之首 考虑两个字符串 一般都需要在状态中记录下当前分别在各个串的哪个位置 那么前两维我们就定义出来了 f[i][j]f[i][j]f[i][j]表示在A串中进行到前i位,B串进行到前j位 等等,这样的定...

Faithfully-xly的博客 327

分区dp求字符串在另外一个字符串中所有子序列形式的出现次数

假设有s1=abaaaba,我们希望求s2=ab的出现次数那么我们可以使用这样的思路对ab进行分区间,也就是a,ab,b 分别代表了f[1,1] f[1,2] f[2,2]三个区间当我们开始遍历s1时,可以得出a对这三个区间的影响a:得到结果在只有a的情况下的结果b现在有了ab情况下的结果大致的转移结果就是如上所述那么如何来表示这个dp转移方程呢?

ccdme的博客 1180

区间DP(3)字符串类型进阶

下面是我这个初学者花了将近一天研究出来的题,对于字符串类型终于算是入门了 看下这题,题目在POJ-2955上,自己找。 题目意思我就不介绍了,比经典字符串多了比较和一些特殊情况 经典字符串比较,比如回文字符串的话,aba最长长度为3,abab最长为3 但是对于这题最长长度为对于 [ ( ] 这种情况,最长长度是2,[ ] [ ] 最长是4 这边就体现了不同与经典字符串的不同 下面我们就来介绍不同的时候哪些是相同的 相同部分,即回文类模板,不同部分,新增判断条件 对于这种问题,都似乎要形成对称

qq_48344603的博客 319

[Leetcode] 每日两题 139 97 -day115字符串DP

今天练两个字符串DP ,字符串DP的难点在于 干扰项比较多,到底怎么定义DP方程这个需要想一想。 139. 单词拆分 这个题就必须从原字符串入手,而不能从单词表入手,从0开始扫描到末尾, dp[i]表示字符串s的前i个字符能否由wordDict中的单词组成。 而这个判定 由 若 i-j 这个字串在列表内且dp[j]=true,那么 dp[i]=true class Solution { public: bool wordBreak(string s, vector<string>&a

weixin_43146899的博客 534

POJ-3267 字符串dp

POJ-3267 The Cow Lexicon 字符串dp 题面: Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words, each containing no more 25 of the characters ‘a’…‘z’. Their cowmunication system, based on mooing, is not very accurate; sometimes they hear wor

m0_50796573的博客 174

codeforces 1096D Easy Problem dp(字符串DP)

codeforces 1096D Easy Problem dp 题目链接[https://codeforces.com/problemset/problem/1096/D] 题意:给你一个字符串,每个字符都有对应的价值,然后给你一个目标串hard,要求这个字符串中没有包含hard的子序列(即,可不连序,如haarrdd也不允许),问删除若干个字符后,达到这个要求,问删除的最小价值。 题解:二维D...

weixin_43843730的博客 400

poj 2194(字符串的DP)

题意:从a、b串组合出c串,如果可以,输出“yes”,否则输出“no” 组合规则:不能乱序,只能顺序从a.b串中去字符。 DP 挺神奇的,一直想学DP ,但是怎么也想不出,真佩服能DP 的神牛们阿,,,,思维太强了。 DP[i]j]表示a的前i个和b的前j个字符组成的c的前i+j个元素,则DP[i][j]=DP[i-1][j]&&DP[i][j-1];所以a[0~i-1]必须和C[i+j-1]中

Weiguang_123的专栏 1129
上一篇: 堆 优先队列
下一篇: 买东西这一类的DP
小小小小葱
博客等级 码龄14年 22粉丝 266原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址