POJ2955 Brackets —— 区间DP

题目链接:https://vjudge.net/problem/POJ-2955

 

Brackets
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 9630 Accepted: 5131

Description

We give the following inductive definition of a “regular brackets” sequence:

  • the empty sequence is a regular brackets sequence,
  • if s is a regular brackets sequence, then (s) and [s] are regular brackets sequences, and
  • if a and b are regular brackets sequences, then ab is a regular brackets sequence.
  • no other sequence is a regular brackets sequence

For instance, all of the following character sequences are regular brackets sequences:

(), [], (()), ()[], ()[()]

while the following character sequences are not:

(, ], )(, ([)], ([(]

Given a brackets sequence of characters a1a2 … an, your goal is to find the length of the longest regular brackets sequence that is a subsequence of s. That is, you wish to find the largest m such that for indices i1, i2, …, im where 1 ≤ i1 < i2 < … < im ≤ n, ai1ai2 … aim is a regular brackets sequence.

Given the initial sequence ([([]])], the longest regular brackets subsequence is [([])].

Input

The input test file will contain multiple test cases. Each input test case consists of a single line containing only the characters (, ), [, and ]; each input test will have length between 1 and 100, inclusive. The end-of-file is marked by a line containing the word “end” and should not be processed.

Output

For each input case, the program should print the length of the longest possible regular brackets subsequence on a single line.

Sample Input

((()))
()()()
([]])
)[)(
([][][)
end

Sample Output

6
6
4
0
6

Source

 

 

题解:

求最多有多少对括号匹配。典型的区间dp。

 

方法一:

1.如果区间[l,r]的两端匹配,则左右各缩进一格,从而转化成处理[l+1, r-1]的区间。

2.不管是否符合条件1,都尝试去枚举分割点,使得整个区间分成两半,这样就可以把大区间的处理转化成两个小区间的处理。

 

记忆化搜索:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <vector>
 6 #include <cmath>
 7 #include <queue>
 8 #include <stack>
 9 #include <map>
10 #include <string>
11 #include <set>
12 using namespace std;
13 typedef long long LL;
14 const int INF = 2e9;
15 const LL LNF = 9e18;
16 const int MOD = 1e9+7;
17 const int MAXN = 100+10;
18 
19 
20 char s[MAXN];
21 int dp[MAXN][MAXN];
22 
23 int dfs(int l, int r)
24 {
25     if(r<=l) return 0;
26     if(dp[l][r]!=-1) return dp[l][r];
27 
28     if( (s[l]=='('&&s[r]==')')||(s[l]=='['&&s[r]==']') )    //如果两端匹配,则可以缩减范围
29         dp[l][r] = dfs(l+1, r-1) + 1;
30     for(int k = l; k<r; k++)    //枚举分割点,分成两半
31         dp[l][r] = max(dp[l][r], dfs(l, k)+dfs(k+1, r));
32 
33     return dp[l][r];
34 }
35 
36 int main()
37 {
38     while(scanf("%s", s+1) && strcmp(s+1, "end"))
39     {
40         memset(dp, -1, sizeof(dp));
41         cout<< dfs(1, strlen(s+1))*2 <<endl;
42     }
43 }
View Code

递推:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <vector>
 6 #include <cmath>
 7 #include <queue>
 8 #include <stack>
 9 #include <map>
10 #include <string>
11 #include <set>
12 using namespace std;
13 typedef long long LL;
14 const int INF = 2e9;
15 const LL LNF = 9e18;
16 const int MOD = 1e9+7;
17 const int MAXN = 100+10;
18 
19 char s[MAXN];
20 int dp[MAXN][MAXN];
21 
22 int main()
23 {
24     while(scanf("%s", s+1) && strcmp(s+1, "end"))
25     {
26         memset(dp, 0, sizeof(dp));
27         int n = strlen(s+1);
28         for(int len = 2; len<=n; len++)
29         {
30             for(int l = 1; l<=n-len+1; l++)
31             {
32                 int r = l+len-1;
33                 if( (s[l]=='('&&s[r]==')') || (s[l]=='['&&s[r]==']') )
34                     dp[l][r] = dp[l+1][r-1] + 1;
35                 for(int k = l; k<r; k++)
36                     dp[l][r] = max(dp[l][r], dp[l][k]+dp[k+1][r]);
37             }
38         }
39         printf("%d\n", dp[1][n]*2);
40     }
41     return 0;
42 }
View Code

 

 

方法二:

1.可知一个符号最多只能与一个符号匹配,那么对于当前的符号,我们就枚举其他符号与其匹配(不管是能匹配成功)。

2.假设区间为 [l, r],为l枚举匹配符号,当枚举到k位置时,就把区间分割成了两部分:[l+1, k-1] 和 [k+1, r] 。从而就把大区间的求解转化为小区间的求解。

 

记忆化搜索:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <vector>
 6 #include <cmath>
 7 #include <queue>
 8 #include <stack>
 9 #include <map>
10 #include <string>
11 #include <set>
12 using namespace std;
13 typedef long long LL;
14 const int INF = 2e9;
15 const LL LNF = 9e18;
16 const int MOD = 1e9+7;
17 const int MAXN = 100+10;
18 
19 char s[MAXN];
20 int dp[MAXN][MAXN];
21 
22 int dfs(int l, int r)
23 {
24     if(r<=l) return 0;
25     if(dp[l][r]!=-1) return dp[l][r];
26 
27     dp[l][r] = dfs(l+1, r);
28     for(int k = l+1; k<=r; k++)
29     {
30         int ismatch = (s[l]=='('&&s[k]==')')||(s[l]=='['&&s[k]==']');
31         int tmp =  dfs(l+1, k-1)+dfs(k+1, r)+ismatch;
32         dp[l][r] = max(dp[l][r], tmp);
33     }
34     return dp[l][r];
35 }
36 
37 int main()
38 {
39     while(scanf("%s", s+1) && strcmp(s+1, "end"))
40     {
41         memset(dp, -1, sizeof(dp));
42         cout<< dfs(1, strlen(s+1))*2 <<endl;
43     }
44 }
View Code

递推:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <vector>
 6 #include <cmath>
 7 #include <queue>
 8 #include <stack>
 9 #include <map>
10 #include <string>
11 #include <set>
12 using namespace std;
13 typedef long long LL;
14 const int INF = 2e9;
15 const LL LNF = 9e18;
16 const int MOD = 1e9+7;
17 const int MAXN = 100+10;
18 
19 char s[MAXN];
20 int dp[MAXN][MAXN];
21 
22 int main()
23 {
24     while(scanf("%s", s+1) && strcmp(s+1, "end"))
25     {
26         memset(dp, 0, sizeof(dp));
27         int n = strlen(s+1);
28         for(int len = 2; len<=n; len++)
29         {
30             for(int l = 1; l<=n-len+1; l++)
31             {
32                 int r = l+len-1;
33                 dp[l][r] = dp[l+1][r];
34                 for(int k = l+1; k<=r; k++)
35                 {
36                     int ismatch = (s[l]=='('&&s[k]==')')||(s[l]=='['&&s[k]==']');
37                     dp[l][r] = max(dp[l][r], dp[l+1][k-1]+dp[k+1][r]+ismatch);
38                 }
39             }
40         }
41         printf("%d\n", dp[1][n]*2);
42     }
43     return 0;
44 }
View Code

 

转载于:https://www.cnblogs.com/DOLFAMINGO/p/7927421.html

【推荐100个unity插件之7】使用BehaviorDesigner插件制作BOSS的AI行为树 Behavior Designer是一个行为树插件,是一款为了让策划,程序员,美术人员方便使用的可视化编辑器。Behavior Designer提供了强大的AP1可以让你轻松的创建tasks(任务),配合uScript和PlayMaker这样的插件,可以不费吹灰之力就能够创建出强大的Al系统,而无需写行代码。(不懂PlayMaker的,我后面在单独出文章介绍一下,可以期待一下) 阅读详情

相关推荐

Codex CLI 接入智谱 GLM-5.1 完整教程

Codex CLI 是 OpenAI 推出的命令行 AI 编程工具,支持自主读取文件、执行命令、编写代码等操作,是目前最火的终端 AI 编程工具之一。通过 CLIProxyAPI 代理,我们成功将 Codex CLI 与智谱 GLM-5.1 模型对接,核心在于解决 Responses API 与 Chat Completions API 的协议转换问题。✅成熟稳定:CLIProxyAPI 社区活跃(4.7k fork),持续维护✅完整兼容:支持流式/非流式、function calling✅低成本。

u011831527的博客 2594

【区间DP first】POJ 2955 Brackets

POJ 2955 Brackets 如果s[st] == s[ed],那么dp[st][ed] = dp[st + 1][ed - 1] + 2。(这个放在枚举断点之前)其实想想确实是这样的,两端相等,那么就该初始化为去头去尾的中间的子串的dp值再加上2 然后就开始枚举断点,更新dp为尽可能的大,大区间等于两个小区间相加 区间DP的一般步骤: 枚举长度 枚举起点 枚举断点(更新dp)...

L_X_ 213

手把手教你复现IEEE 2025高光谱图像盲超分算法DBSR(附开源代码与避坑指南)

本文详细介绍了如何从零复现IEEE 2025高光谱图像盲超分算法DBSR,包括环境配置、数据预处理、核心模块解析、训练策略及常见问题解决方案。特别针对开源代码中的关键步骤和潜在问题提供了实用指南,帮助研究者和开发者高效实现Deep blind super-resolution技术,适用于遥感、医疗等领域的图像增强应用。

weixin_42524708的博客 417

POJ 2955 Brackets 区间DP

POJ 2955 Brackets 区间DP 题目链接:POJ 2955 Brackets  题意:求字符串中匹配的括号数*2,字符串长度 分析:区间DP入门题,dp[i][j] 表示区间[i, j]匹配数 *2 写出状态方程: if(i, j匹配)  dp[i][j] = dp[i + 1][j - 1] + 2; dp[i][j] = max(dp[i][j], dp

Fighting! 544

Verilog仿真必备:FSDB dump命令全解析与实战配置指南

本文深入解析了Verilog仿真中FSDB波形记录的核心命令与实战配置技巧。针对大规模SoC验证场景,详细介绍了如何通过$fsdbDumpvars、$fsdbDumpfile等命令实现信号精准捕获、文件体积控制和动态启停,并提供了智能化的分层dump策略,帮助工程师在保证调试信息完整性的同时,大幅提升验证效率并有效管理波形数据。

cnn8visionary的博客 352

coze+飞书多维表格,批量分析小红书笔记,关键还能获取图片(附保姆级教程)

通过coze工作流,一键同步小红书账号和笔记链接到飞书多维表格,效率飞升~

qq_24403067的博客 4181

poj 2955 Brackets 区间DP

传送门:poj 2955 Brackets题目大意判断给定的字符串满足条件的个数,(由’[‘,’]’,’(‘.’)’构成的序列)解题思路dp[i][j]表示i到j这个区间的最大匹配数目! 这个dp[i][j]有两个状态专一的过程, 1. 如果i位置和j位置的括号是匹配的那么,转移方程就变为了dp[i+1][j-1] 2. 然后我们将这个区间拆分为两个区间,然后我们从小到大枚举i到j这个区间,每

woshinannan的专栏 425

基于STM32设计的遥控小车(手机APP+GPS+温湿度+ESP8266)

一、环境介绍 小车主控MCU: STM32F103ZET6 STM32程序开发IDE: keil5 STM32程序风格: 采用寄存器方式开发,注释齐全,执行效率高,方便移植 手机APP: 采用QT设计,程序支持跨平台编译运行(Android、IOS、Windows、Linux都可以编译运行,对应平台上QT的环境搭建,之前博客已经发了文章讲解) 硬件包含: 淘宝购买的完整一套4轮遥控小车(采用STM32F103ZET6作为主控板)、DHT11温湿度传感器、中科微GPS模块、ESP8266 ...

6万+

POJ2955 Brackets 【区间DP】

题目链接:POJ-2955 kuangbin带你飞【专题二十二】 区间DP 题目描述: We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a regular brackets sequence, if s is a regular brackets...

Hang_ccccc的博客 183

室内无线传播损耗分析与传播模型验证课程设计

室内无线传播损耗分析与传播模型验证课程设计

a_zxswer的博客 190

【Python_PySide6学习笔记(二十四)】菜单栏QMenuBar类的基本用法

此篇文章中介绍 PySide6 中 QMenuBar 类的基本用法,包括"创建菜单栏"、"创建一级菜单"、"创建二级菜单"等,会持续更新,有需要的读者可以点赞收藏,也欢迎在评论区进行讨论。

禾戊之昂的博客 1628

【区间dp】 poj 2955 Brackets

首先补充点关于区间dp的知识 区间DP是一类在区间上进行动态规划的最优问题,一般是根据问题设出一个表示状态的dp,可以是二维的也可以是三维的,一般情况下为二维。然后将问题划分成两个子问题,也就是一段区间分成左右两个区间,然后将左右两个区间合并到整个区间,或者说局部最优解合并为全局最优解,然后得解。区间dp专辑 题意:给定一个字符串,问最长匹配的括号长度是多少? dp[i][j]代表第i...

iroy33的博客 332

基于ZYNQ PL的AD7606数据采集与FFT实时频谱分析:从硬件到创新实现

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-kKnmpgJm-1750295287594)(https://example.com/fft_plot.png)]本文涉及代码已在Xilinx ZCU102开发板与AD7606评估板上验证通过,采样率支持200KSPS@8通道,FFT计算延迟<1ms。传统MCU+DSP方案难以兼顾速度与功耗,而ZYNQ的PL+PS架构为这一问题提供了完美解决方案。本文实现的ZYNQ PL方案突破了传统处理器的性能瓶颈,通过。

QQ_778132974的博客 342

POJ 2955 Brackets 区间dp

题意: 给出一个由 '(', ')', '[', ']' 组成的序列, 求最长的合法括号序列的长度. 思路: 一开始我的想法是dp[i][j]维护i到j之间合法序列的长度. 然后单开数组维护这个区间头上多出的(和[,以及尾上的)和],但是这样是不对的. 因为同样是i到j的区间, 可能会有不同个数的多余括号. 这样就产生了状态重叠(多个状态用了同一个位置表示). 这样, 就只能开4维空间, 但...

swqeaaa的博客 228

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

POJ 2955 Brackets 【区间DP】

题目链接 题意 给一串包含中括号和小括号的字符串,求其括号匹配正常的顺序(不一定连续)子串中的(最长串) 分析 状态 区间问题的一般处理方法:设dp[i][j]⇔与j间最长满足要求子串长度 状态转移方程 如果这个区间两个端点的括号是匹配的,那么它可以是由去掉两端点的串加上2转移而来,比如([]) dp[i][j]=max(dp[i][j]...

babao9492的博客 113

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【区间DP】POJ2955.Brackets

题目 POJ2955.Brackets We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a regular brackets sequence, if sss is a regular brackets sequence, then (s) and [s] are regular brackets sequences, and if aaa and bbb a

Carry_hkr的博客 541

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

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

POJ2955 Brackets 区间DP

POJ2955 Brackets 区间DP

htrdchh的博客 127

POJ 2955——Brackets【区间DP】

题目传送门 Description We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a regular brackets sequence, if s is a regular brackets sequence, then (s) and [s]...

NIRVANA REBIRTH 332

POJ2955 Brackets 题解 区间DP

题目链接:http://poj.org/problem?id=2955【题目描述】《规则的括号序列》我们定义一个字符串序列为“规则的括号序列”当且仅当它满足如下条件:1、空字符串是规则的括号序列;2、如果字符串 s 是一个规则的括号序列,那么 (s) 和 [s] 也是规则的括号序列;3、如果字符串 a 和 b 都是规则的括号序列,那么 ab 也是规则的括号序列;4、除此之外的字符串都不能称为规则的...

weixin_30693183的博客 165

POJ2955-Brackets【区间DP】

We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a regular brackets sequence, ifsis a regular brackets sequence, then (s) and [s] are regular brac...

独钓门前月 150

poj 2955 Brackets 【区间DP】

题意: 给你一个只包括大小括号的串,一个合法串的定义如下: 1.空串是合法的; 2.若s为合法的,则 [s] (s) 也为合法的; 3.若 a,b为合法的 , ab 也是合法的。 给你一个长度小于100的串,求其所包含的的最长的合法串所包涵的字符数。 解法: 经典区间dp,括号匹配问题,o(n3) 状态: dp[i][j] 表示 s[i]到s[j]字符区间内的最长长度。

Arrows' Dairy 531

poj2955 Brackets 简单区间dp

// poj2955 简单区间dp // d[i][j]表示i到j区间所能形成的最大匹配序列 // dp[i][j] = max(dp[i][k]+dp[k+1][j]){i<k<j} // dp[i][j] = max(dp[i+1][j-1]+2) if (s[i] match s[j]) // // 记忆化搜索的时候,将dp[i][i] = 0 ,其他赋值成-1; // // 做题的时候刚开

TIMELIMITE的专栏 986

POJ 2955 Brackets(区间DP)

嗯... 题目链接:http://poj.org/problem?id=2955 一道比较经典的区间dp,注意首先更新dp,然后再转移,转移的时候并没有什么代价,即dp[i][j] = max(dp[i][j], dp[i][k] + dp[k + 1][j] AC代码: 1 #include<cstdio> 2 #include<io...

weixin_30408739的博客 208

poj 2955 Brackets(区间dp)

Description We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a regular brackets sequence, ifsis a regular brackets sequence, then (s) an...

dielucuan8830的博客 67

【POJ 2955】Brackets(区间DP)

【POJ 2955】Brackets(区间DP)入门级区间DP问最长的匹配括号长度。只包含()和[] 要求匹配括号不可交叉,即([)]这种不计入因为不计交叉情况,转移就很直白。枚举区间长度l,转移为if( (str[i] == '(' && str[i+l-1] == ')') || (str[i] == '[' && str[i+l-1] == ']') ) dp[i][i+l-1]

ACMer' 1203
上一篇: HDU3709 Balanced Number —— 数位DP
下一篇: POJ1651 Multiplication Puzzle —— DP 最优矩阵链乘 区间DP
alince20008
博客等级 码龄12年 5粉丝 152原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址