POJ 2955 —— Brackets

说说通用报表控件 我们已经开发有2款WINCC报表控件,一种是固定模板,一种是自定义模板。但是它们有个共同特点,就是数据都是来自WINCC的归档数据库。使用WINCC归档数据库的好处是不需要自己写脚本保存数据。但是有些情况下,我们需要自己保存数据,或者第三方系统通过数据表的方式给我们提供数据。那这样的话,我们之前的两款控件就不支持了。正好有个客户有类似需要,于是加了一天班写了个通用报表控件。之所以说是通用,是因为它可以插入任何支持.NET控件的组态软件中,比如WINCC、IFIX等。并且它不依赖于组态软件自己... 阅读详情
题目:http://poj.org/problem?id=2955
 
状态定义:dp[i][j] := 区间为i~j时的最大长度
方法1(推荐):
  dp[i][j] = min(dp[i+1][j],dp[i+1][k-1]+dp[k+1][j]+2)(i<=k<=j&&i和k是一对括号)
方法2:
  dp[i][j] = max(dp[i+1][j-1]+2, dp[i][k] + dp[k+1][j]) (当s[i]与s[j]括号匹配, i<=k<j)

      = max(dp[i][k] + dp[k+1][j]) (当 s[i]与s[j]括号不匹配, i<=k<j)

 

方法一: 

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
using namespace std;

char s[105];
int dp[105][105];
const char end[4] = "end";

int main ()
{
    while(scanf("%s", s) != EOF && strcmp(s, end)) {
        int len = strlen(s);
        
        for(int step=1; step<len; step++) {
            for(int i=0; i+step<len; i++) {
                int j = i + step;
                dp[i][j] = dp[i+1][j];
                for(int k=i+1; k<=j; k++) {
                    if(s[i]=='(' && s[k]==')' || s[i]=='[' && s[k]==']') {
                        if(dp[i+1][k-1]+dp[k+1][j]+2 > dp[i][j]) {
                            dp[i][j] = dp[i+1][k-1]+dp[k+1][j]+2;
                        }
                    }
                }
            }
        }
        printf("%d\n", dp[0][len-1]);
    }
    
    return 0;
}

 

 

方法二:

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
using namespace std;

char s[105];
int dp[105][105];
const char end[4] = "end";

int main ()
{
    while(scanf("%s", s) != EOF && strcmp(s, end)) {
        int len = strlen(s);
for(int step=1; step<len; step++) { for(int i=0; i+step<len; i++) { int j = i+step; //删去不必要的字符 if(s[i]!='(' && s[i]!='[') { dp[i][j] = dp[i+1][j]; } else if(s[j]!=')' && s[j]!=']') { dp[i][j] = dp[i][j-1]; } else { dp[i][j]=0; if(s[i]=='(' && s[j]==')' || s[i]=='[' && s[j]==']') { dp[i][j] = dp[i+1][j-1]+2; } for(int k=i; k<j; k++) { dp[i][j] = max(dp[i][j], dp[i][k] + dp[k+1][j]); } } } } printf("%d\n", dp[0][len-1]); } return 0; }

 

 

 

大语言模型(LLM)在组合优化中的新突破:LLM-LNS与FunSearch性能对比 本文深入探讨了大语言模型(LLM)在组合优化中的创新应用,重点对比了LLM-LNS与FunSearch两种方法的性能差异。研究表明,LLM-LNS在物流路径规划、资源调度等场景中展现出显著优势,其双层自演化架构能有效平衡探索与利用,相比传统方法提升效率约43%。文章还提供了实践选择指南,帮助开发者根据具体需求选用合适的技术方案。 阅读详情

相关推荐

直流无刷减速电机选型指南:从KV值到霍尔传感器,新手必看的5个关键参数

本文详细解析直流无刷减速电机选型的5个关键参数,包括KV值、转矩、电流与功率、减速比选择以及霍尔传感器配置。通过实战案例和避坑策略,帮助工程师精准匹配电机性能与负载需求,提升工业自动化设备的可靠性和效率。特别强调霍尔传感器在精准控制中的关键作用。

alice7model的博客 620

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! 543

LTspice基础教程-028.Timestep too small

Q: “Timestep too small” error message A: If the LTspice program can’t find a solution for the guessed time step, then the program decreases the time step and tries again. This can’t work forever. If...

gaoyong_wang的博客 2万+

【区间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

通俗易懂的图解二叉搜索树、AVL树和红黑树

搜索是一种很常见的需求,当数据较多时,如何找到目标对象时,即需要搜索查找。 那么如何快速找到目标呢,最朴素的思想就是暴力查找,一个一个对比。 显然,当数据量增大时,我们需要优化查找方法获取更快的查找速度,我们可以通过维护一个有序数组,从而实现二分查找,查找速度从O(n)降为O(longn)。 但是数组并不便于插入和删除,链表便成为了最好的选择。 既然是采用二分查找,那么不如直接按照查找的步骤维护一种数据结构,于是二叉搜索树出现了。 二叉搜索树的性质为: 若左子树不为空,则左子树上所有节点值都小于根结点值;

暗色光的博客 758

弘玑RPA进阶攻略

01.弘玑RPA产品概要。02.设计器的安装与卸载。03.设计器特性与使用。

长安诗社社长@-梁瀚文- https://github.com/HevnChin https://gitee.com/HevnChin 3644

区间dp入门:poj 3280 Cheapest Palindrome poj 2955 Brackets

poj 3280Cheapest PalindromeKeeping track of all the cows can be a tricky task so Farmer John has installed a system to automate it. He has installed on each cow an electronic ID tag that the system w...

obsorb_knowledge的博客 218

药物对接仿真软件:HADDOCK_(9).结果分析方法

HADDOCK是一种强大的药物对接仿真工具,通过对生成的输出文件进行详细的分析,我们可以验证仿真结果的可靠性,并为进一步优化药物设计提供依据。常见的分析方法包括解读输出文件、使用可视化工具进行结构分析、评估对接模型的稳定性和准确性等。通过这些步骤,我们可以更全面地了解受体和配体的结合模式,从而提高药物设计的成功率。

kkchenjj的博客 1006

POJ 2955 Brackets

POJ 2955 Brackets #include #include #include #include #include using namespace std; //dp[i][i+j] = max{dp[i][k]+dp[k+1][i+j], dp[i-1][i+j-1]+(s[i]s[i+j]是否匹配)} | k:i...i+j-1; string s1; int dp[

某科学的程序员 489

【用unity实现100个游戏之18】从零开始制作一个类CSGO/CS2、CF第一人称FPS射击游戏——基础篇1(附项目源码)

生存和射击游戏一直是我的最爱,说起3D最普遍的应该就是射击系统了,你可以在任何情况下加入射击功能,所以我写下了这篇FPS开发记录。希望对你有帮助。在这个项目中,你将学习如何设计和实现射击系统、武器系统、玩家控制、场景设计等方面的内容。通过这个项目,你将深入了解游戏开发中的许多核心概念和技术,并且在实践中不断提升自己。本项目将带你从零开始逐步实现一个完整的第一人称射击游戏,并且会逐步引入一些高级功能,如特效、声音等。

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 5498

DCMTK编译

dcmtk-3.6.4 使用Unicode?dcmtk的编译选项里没有关于Unicode的选项,OFString的接口里明确使用了OFString(char*)作为构造函数参数,所以,我们可以假设不能够自己擅自在CMakeList.txt里增加一行 add_definitions(-DUNICODE -D_UNICODE) 来强制使用Unicode编码。 亲测:加了之后编译不过 void...

C++ 爱好者 make_it_simple888 1733

poj 2955 Brackets

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 r...

502

抖音 X-Gorgon 加密算法逆向与 Python 爬虫实战(2026 最新版)

抖音(TikTok 国内版)作为日活超 8 亿的超级 App,其反爬体系在国内互联网中属于顶级难度。核心签名参数X-Gorgon和X-Khronos是几乎所有业务接口(视频详情、评论、搜索、用户主页)的“通行证”。没有正确的 Gorgon 签名,服务器直接返回403或。市面上的教程大多停留在2023 年之前的 V4 版本,而抖音在 2025 年底全面升级到了V6 协议,算法结构、加密常数、混淆方式全部重构。

2201_76125261的博客 345

Brackets POJ - 2955

http://poj.org/problem?id=2955 枚举出左右端点i j后 如果ij正好是一对括号 那就将dp[i][j]从dp[i+1][j-1]先转移过来 因为只有这种情况会产生更长的合法序列 然后就是区间DP的套路 枚举一下中点即可 #include &lt;cstdio&gt; #include &lt;cstring&gt; #include &lt;algori...

sunyutian1998的博客 199

深度学习工具包 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")

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

POJ-2955-Brackets

POJ-2955-Brackets 传送门 这道题是简单的区间dp~ 括号最大匹配 题目大意:给你一个括号序列。让你求出最大长度的子括号匹配序列~文件形式输入 很简单啦~ dp[i][j]表示第i个括号到第j个字符的最大匹配长度~ 然后初始化为0 如果下面式子成立 s[i] == ‘(’ && s[j] == ‘)’ || s[i] == ‘[’ && s[j] =...

qq_44624316的博客 115

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

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的专栏 424

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

POJ2955 Brackets

区间DP基础

H992109898的博客 464

poj2955 brackets

基础区间dp #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int dp[107][107]; char s[107]; int main() { while(scanf("%s",s)!=EOF&a...

weixin_45885433的博客 155

[POJ2955]Brackets

题面描述 我们给出了正则括号序列的如下归纳定义: · 空序列是正则括号序列 · 如果s是正则方括号序列,那么(s)和[s]是正则方括号序列 · 如果a和b是正则括号序列,那么ab是正则括号序列 · 没有其它序列是正则括号序列 例如,以下所有字符序列都是正则方括号序列: () [] (()) ()[] ()[()] 而以下字符序列都不是: ( j ) 给定字符的方括号序列s,找到s的正则括...

weixin_30302609的博客 204

POJ 2955 Brackets 区间dp

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

swqeaaa的博客 227

POJ2955——Brackets

Brackets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3341   Accepted: 1717 Description We give the following inductive definition of a “regular brackets”

Alex 734

POJ-2955 Brackets

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 bracke...

slass-mot-odet 183
上一篇: 求若干矩形的不重叠面积 —— 模拟 + 优化
下一篇: Light oj 1422 - Halloween Costumes
AcIsFun
博客等级 码龄10年 1粉丝 92原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值