POJ 1141 Brackets Sequence

Windows域账户无管理员权限也能装软件?3步搞定UAC设置(附安全提醒) 本文探讨了在Windows域环境中,如何通过配置用户账户控制(UAC)实现临时提权,让无管理员权限的域账户也能安装软件。文章详细介绍了三步走策略:临时加入本地管理员组、调整UAC行为以及至关重要的权限回收,并提供了脚本化部署方案与安全实践指南,旨在平衡企业IT管理的效率与安全。 阅读详情

Brackets Sequence
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 13305 Accepted: 3585 Special Judge

Description

Let us define a regular brackets sequence in the following way: 

1. Empty sequence is a regular sequence. 
2. If S is a regular sequence, then (S) and [S] are both regular sequences. 
3. If A and B are regular sequences, then AB is a regular sequence. 

For example, all of the following sequences of characters are regular brackets sequences: 

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

And all of the following character sequences are not: 

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

Some sequence of characters '(', ')', '[', and ']' is given. You are to find the shortest possible regular brackets sequence, that contains the given character sequence as a subsequence. Here, a string a1 a2 ... an is called a subsequence of the string b1 b2 ... bm, if there exist such indices 1 = i1 < i2 < ... < in = m, that aj = bij for all 1 = j = n.

Input

The input file contains at most 100 brackets (characters '(', ')', '[' and ']') that are situated on a single line without any other characters among them.

Output

Write to the output file a single line that contains some regular brackets sequence that has the minimal possible length and contains the given sequence as a subsequence.

Sample Input

([(]

Sample Output

()[()]

Source

/*

http://acm.pku.edu.cn/JudgeOnline/problem?id=1141

动态规划,与最优二叉查找树类似,从下往上,从小到大,遍历长度len,然后遍历位置k

*/

#include <iostream>

#define MAX_N 100
using namespace std;

char input[MAX_N + 1];
int len;
int pos[MAX_N + 1][MAX_N + 1];
int minV[MAX_N + 1][MAX_N + 1];

void print(int f, int t)
{
    if(f > t)
        return;
    if(pos[f][t] == -1)
    {
        cout<<input[f];
        print(f + 1, t - 1);
        cout<<input[t];
    }
    else if(f == t)
    {
        char type = input[f];
        if(type == ')' || type == '(')
            cout<<"()";
        else
            cout<<"[]";
    }
    else
    {
        print(f, pos[f][t]);
        print(pos[f][t] + 1, t);
    }
}

bool match(char t1, char t2)
{
    return ((t1 == '(' && t2 == ')') || (t1 == '[' && t2 == ']'));
}
int main()
{
    char ch;
    len = 0;
    while((ch = getchar()) != 10)
    {
        input[++len] = ch;
    }
    int i, j;
    for(i = 1; i <= len; i++)
    {
        for(j = 1; j <= len; j++)
        {
            if(i == j)
                minV[i][j] = 1;
        }
    }
    int l, k;
    for(l = 2; l <= len; l++)
    {
        for(i = 1; i <= len - l + 1; i++)
        {
            j = i + l - 1;
            int minVal = INT_MAX, minPos = 0, curVal;
            for(k = i; k < j; k++)
            {
                curVal = minV[i][k] + minV[k + 1][j];
                if(curVal < minVal)
                {
                    minVal = curVal;
                    minPos = k;
                }
            }
            if(match(input[i], input[j]))
            {
                curVal = minV[i + 1][j - 1];
                if(curVal < minVal)
                {
                    minVal = curVal;
                    minPos = -1; //min trim head and tail
                }
            }
            minV[i][j] = minVal;
            pos[i][j] = minPos;
           
        }
    }
    print(1, len);
    cout<<endl;
    return 0;
}

在macOS上使用GitHub的超详细指南 GitHub:免费的远程仓库,可用来托管自己的开源项目。它利用了Git强大的克隆和分支功能,让我们参与别人的开源项目和让别人参与自己的开源项目变得简单高效。 阅读详情

相关推荐

CATIA CAA 二次开发去除面内开孔

测试模型: 代码说明:以下代码在拓扑级去除Face的内部loop,更改后的Body通过oispBody参数输出。主要使用CATSmartBodyDuplicator拓扑操作实现 HRESULT CAAStarterCmd::RemoveHoleOnFace(CATBody_var &ispBody,CATBody_var &oispBody){ CATLISTP(CATCell)olistFace; ispBody->GetAllCells(olistFace,2); CATF

weixin_45445751的博客 2265

POJ 1068(模拟)

题目链接:http://poj.org/problem?id=1068 题意:一个括号表达式可以按照如下的规则表示,就是每个右括号之前的左括号数。比如(((()()()))),每个右括号之前的左括号数序列为P=4 5 6 6 6 6,而每个右括号所在的括号内包含的括号数为W=1 1 1 4 5 6.现在给定P,输出W。 思路:直接模拟。根据p先模拟出原来的合式公式,然后从右向左判断匹配

To be excellent! 435

苍穹外卖项目面试总结话术

美食速递这个项目最初是我参与制作的大创项目,是一款为中南学生提供校园外卖送至宿舍服务的软件,包含系统管理后台和小程序端两部分。其中系统管理后台主要提供给食堂内部员工使用,可以对食堂各个窗口、员工、订单、菜品等进行维护管理;小程序端可以在线浏览菜品、添加购物车、下单等,由学生兼职做跑腿送餐上门服务。这是个前后端分离的项目,我主要是负责后端的用户登录、员工管理,菜品管理,订单管理模块的编码实现。

qq_45195447的博客 1万+

POJ-1141:Brackets Sequence(括号序列)

POJ-1141:Brackets Sequence(括号序列) 一、问题描述 Let us define a regular brackets sequence in the following way: 让我们用以下的方式来定义一个常规括号序列: Empty sequence is a regular sequence. 空的序列是一个常规序列 If S is a regular sequence, then (S) and [S] are both regular sequences. 如果S

soulandlove的博客 1417

STM32L151C8T6低功耗实战:RTC闹钟唤醒停机模式的配置与优化

本文详细介绍了如何在STM32L151C8T6微控制器上配置与优化RTC闹钟唤醒停机模式,以实现极致的低功耗设计。文章从核心原理出发,结合STM32CubeMX配置实战,深入讲解了进入停机模式前的关键准备工作、唤醒后的系统恢复流程,并分享了将功耗降至个位数微安级的深度优化技巧与常见问题解决方案。

weixin_29166013的博客 301

RTL8306MB交换芯片驱动开发避坑指南:从硬件接线到SDK移植全流程解析

本文详细解析了RTL8306MB交换芯片驱动开发的全流程,重点从硬件接线、SDK移植到实战调试。针对RMII模式下的常见问题,特别是TXEN与RXDV信号交叉连接等关键“坑点”,提供了清晰的排查指南和解决方案,旨在帮助嵌入式工程师高效完成网络设备开发。

277

石子合并(区间DP-加西亚-瓦克斯(GarsiaWachs)算法.)

P1775 石子合并(弱化版) - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)可解决 n

shuyuan12346的博客 810

TS808效果器制作教程

TS808效果器制作教程 可以在立创商城购买到大部分的电阻电容和IC,音频接口,踩钉,电位器和电源接口可以去某宝看看都买得到的。链接https//pan.baidu.com/s/1QId1eIE3fJ2u5NLBSISvGA。安装过程过于繁琐,把所有元器件按照图纸焊接完成就可以调试了,祝你们成功!这是TS808经典效果器制作过程的记录。IC是JRC4558。...

qq_18948149的博客 3427

POJ1141 动态规划,空间优化

本来一个括号匹配的题目,在学习完数据结构的栈之后,我以为自己无敌了,直接一个栈上去 Time Limit Exceeded .......... 当时我稍微想了下为啥,没想出来,趁现在写博客的时候再想想看, ............ 还是想不出来 后来发现,我学的那个栈的方法好像只能用来检测括号序列是否匹配,但是无法做到最小匹配.... 然后发现POJ上还有一个题目2

Peter的脱发日记 466

港口集装箱码头运营FlexSim仿真

列队4中的集装箱会根据不同类型的集装箱会放置在不同的堆场,因此根据前面对集装箱设置的标签Type的数值不同,设置不同的发送端口。集装箱到达列队3后,会有70%的集装箱到达堆场,30%的集装箱运出港口,因此在Queue列队3的Flow界面设置按照百分比发送端口,其中70%发送到端口1,即发送到列队4等待进入堆场,30%发送到端口2,即发送至出闸口。通过上述对比表格可以看出,当集卡数量在10的时候,岸桥和场桥的设备利用率达到了最高,当集卡数量为12的时候场桥1和场桥3的利用率有所下降,因此综合考虑。

m0_72514516的博客 1331

Centos 7 Linux 安装单机 Hadoop(HDFS):下载、安装、配置、测试

本文详细介绍了在 CentOS 7 系统上安装与配置单机 Hadoop(HDFS)的完整流程,涵盖 JDK 环境准备、Hadoop 安装包下载与部署、核心配置文件(core-site.xml、hdfs-site.xml 等)修改、SSH 免密登录设置、HDFS 格式化及服务启动,并通过命令行与 Web 界面验证 HDFS 和 YARN 功能,适合 Hadoop 初学者快速搭建本地测试环境。

寒水馨 · 轻量级技术文档 · hanshuixin.org 3235

POJ-1141-Brackets Sequence

题目链接: Go! 题目大意: ​ 给你一个长度不超过 100100100 且只包含 (,),[,](,),[,]( , ) , [ , ] 四种字符的字符串 sss,添加 最少 的字符使其变成一个合法的字符串,输出这个合法的字符串。 合法字符串的定义: EmptyEmptyEmpty sequencesequencesequence isisis ...

dreams___的博客 308

开源项目-智能算法中台管理系统

智能算法中台管理系统,系统主要有样本中心,算法中心,模型中心等模块

u010479989的博客 3001

POJ 1141 Brackets Sequence

POJ  1141;链接:http://poj.org/problem?id=1141 题目: Brackets Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23638   Accepted: 6665   Special Judge

u010084308的专栏 1189

Camera2Demo

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

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

动态规划 Brackets Sequence poj 1141

题目连接:http://poj.org/problem?id=1141 题目大意:给出一串括号序列(只包含小括号和中括号),求包含次子序列的长度最小的regular brackets sequence。其中regular brackets sequence定义如下: 1.空序

凌风 2921

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

POJ 1141_Brackets Sequence

Description Let us define a regular brackets sequence in the following way:  1. Empty sequence is a regular sequence.  2. If S is a regular sequence, then (S) and [S] are both regular sequences

骐骥一跃不能十步,驽马十驾功在不舍 761

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

poj1141-Brackets sequence

题目链接 题意:给定一括号序列,求出添加括号数最小的完整序列 解法:区间DP 定义dp[i][j]表示题目所给字符串s中从左至右字符i至j这一区间段括号序列构成完整序列所需添加的最小括号数; 根据i与j的大小对dp[i][j]进行初始化,i==j显然为1,i>j不符合定义中从左至右意为空序列即0,i<j因是取最小值则初值设为相对较大; 设阶段r为序列长度,状态为i为...

My优快云5008的博客 301

poj 1141Brackets Sequence

Brackets Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31629   Accepted: 9114   Special Judge Description Let us define a regular brackets seque

wo的只属于我 395

poj 1141 Brackets Sequence(DP第一弹)

poj   1141   Brackets Sequence                      题目链接:http://poj.org/problem?id=1141 DP 题目大意:一个字符串只有方括号和圆括号四种字符,规定合法序列,要求将输入序列修改成最短合法序列输出。 合法序列定义:     (1)空序列是一个合法的序列。     (2)如果S是一个合法序列,那么(S)和[

slicer的技术交流栈 824

Poj 1141 Brackets Sequence

DescriptionLet us define a regular brackets sequence in the following way: 1. Empty sequence is a regular sequence. 2. If S is a regular sequence, then (S) and [S] are both regular sequences. 3.

Follow My Heart 395

POJ 1141 —— Brackets Sequence

题目:http://poj.org/problem?id=1141 区间DP + 构造出DP的解 这里有两种思路都是对的:   第一种(推荐):dp[i][j] := 区间i~j最少需要加多少字符使得它符合括号匹配,然后构造出一个DP的解就好了   第二种:dp[i][j] := 区间i~j符合括号匹配的最长子序列的长度,然后在构造最长子序列的过程中标记哪些字符本身就已经匹配完毕了,然后对

AcIsFun的博客 316

poj 1141 Brackets Sequence

感想:较好的入门题,关键这里可以让你学到记录路径的方法,也可以算做dp记路径的入门题了吧。 思路:   这题的思路关键在于   (A) 或(B)  AB这几种请况,所以在dp的过程中 要找这几种的最小值, 首先   dp[ i ][ i ]肯定是1,因为只有一个单括号的话,必须要来一个括号来进行匹配; 状态转移方程   dp[ i ][ j ] =  min(d

purevegetable 1218

poj1141 Brackets Sequence

(http://www.elijahqi.win/2017/12/28/poj1141-brackets-sequence/) DescriptionLet us define a regular brackets sequence in the following way: Empty sequence is a regular sequence. If S is a regular seque

Elijahqi 225

POJ1141 Brackets Sequence

大致的意思是将一个非规范的序列转化成规范的序列,如 ([(],这是一个非规范的序列,处理之后要求输出规范的序列:()[()],要求就是添加最少的括号。     黑书上通过这题来介绍选择DP的原因之一:递归。     因为序列Si····Sj,可以分成:Si···Sk,Sk+1···Sj,只要d(i,k)+d(k+1,j)最小,则d(i,j)=min(d(i,j),d(i,k)+d(k+1,j)

flyRP的专栏 578

Brackets Sequence poj1141

Brackets Sequence poj1141 题意:给一个括号串,要求输出增加最少的括号,使得整个括号串匹配后的括号序列。 思路:区间dp。记录路径的时候使用pos[i][j]数组,记录i到j中间的分割点,如果不用分割,那么记录为-1,否则是分割点的位置. 输出使用递归即可。 TIP:不要用scanf,会wa掉。用gets来读入。#include<cstdio> #include<io

neuike的博客 335
上一篇: POJ 1137 The New Villa
下一篇: POJ 1142 Smith Numbers
bobten2008
博客等级 码龄18年 153粉丝 157原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值