PKU2192 Zipper(DP+记忆化)

本文介绍了一个经典的字符串组合问题,探讨如何判断第三字符串是否能通过前两个字符串按原顺序交替组合而成。采用动态规划方法实现,并提供了完整的代码示例。

/*
 

Zipper
Time Limit: 1000MS        Memory Limit: 65536K
Total Submissions: 6751        Accepted: 2244

Description
Given three strings, you are to determine whether the third string can be formed by combining the characters in the first two strings. The first two strings can be mixed arbitrarily, but each must stay in its original order.

For example, consider forming "tcraete" from "cat" and "tree":

String A: cat
String B: tree
String C: tcraete

As you can see, we can form the third string by alternating characters from the two strings. As a second example, consider forming "catrtee" from "cat" and "tree":

String A: cat
String B: tree
String C: catrtee

Finally, notice that it is impossible to form "cttaree" from "cat" and "tree".

Input
The first line of input contains a single positive integer from 1 through 1000. It represents the number of data sets to follow. The processing for each data set is identical. The data sets appear on the following lines, one data set per line.

For each data set, the line of input consists of three strings, separated by a single space. All strings are composed of upper and lower case letters only. The length of the third string is always the sum of the lengths of the first two strings. The first two strings will have lengths between 1 and 200 characters, inclusive.

Output
For each data set, print:

Data set n: yes

if the third string can be formed from the first two, or

Data set n: no

if it cannot. Of course n should be replaced by the data set number. See the sample output below for an example.

Sample Input

3
cat tree tcraete
cat tree catrtee
cat tree cttaree

Sample Output

Data set 1: yes
Data set 2: yes
Data set 3: no

Source
Pacific Northwest 2004
*/

 

整个就是从左向右,当出现某个位置S3即不和当前的S1[I]相等又不和当前的S2[J]相等的时候,我们就可以判断这个时候不对了,f[i][j] = 0,接着就往回推到之前的某个分支可以选择其他的地方再开始算(指的是这个意思:比如某个时候(分支)是选择i + 1,这下i + 1推到后来推出0了,那么一路f[i][j] = 0推回到这个分支这次选择j + 1,然后往下推),注意每次递归的时候我们先判断的是当前f[i][j]是不是已经算过了,就是这段代码:

    if(f[i][j]!= -1)
    {
    return f[i][j];
    }

因为当-1的时候是没算过的时候,当为其他值(不管1还是0)就是算过,算过就马上返回不要重复再算。

多源动态最优潮流的分布鲁棒优化方法(IEEE118节点)(Matlab代码实现)内容概要:本文介绍了基于Matlab代码实现的多源动态最优潮流的分布鲁棒优化方法,适用于IEEE118节点电力系统。该方法结合两阶段鲁棒模型与确定性模型,旨在应对电力系统中多源不确定性(如可再生能源出力波动、负荷变化等),提升系统运行的安全性与经济性。文档还列举了大量相关的电力系统优化研究案例,涵盖微电网调度、电动汽车集群并网、需求响应、配电网重构等多个方向,并提供了YALMIP等工具包的网盘下载链接,支持科研复现与进一步开发。整体内容聚焦于电力系统建模、优化算法应用及鲁棒性分析。; 适合人群:具备电力系统基础知识和Matlab编程能力的研究生、科研人员及从事能源系统优化的工程技术人员;熟悉优化建模(如鲁棒优化、分布鲁棒优化)者更佳。; 使用场景及目标:①开展电力系统动态最优潮流研究,特别是含高比例可再生能源的场景;②学习和复现分布鲁棒优化在IEEE118等标准测试系统上的应用;③进行科研项目开发、论文复现或算法比较实验;④获取相关Matlab代码资源与仿真工具支持。; 阅读建议:建议按文档结构逐步浏览,重点关注模型构建思路与代码实现逻辑,结合提供的网盘资源下载必要工具包(如YALMIP),并在Matlab环境中调试运行示例代码,以加深对分布鲁棒优化方法的理解与应用能力。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值