Title DescriptionDescriptionThe definition satisfies the following rule string for the rule sequence, otherwise it is not a rule sequence:1. An empty sequence is a sequence of rules;2. If S is a sequence of rules, then (s), [S],{s} and 3. If both A and B are regular sequences, then AB is also the rule sequence.For example, the following string is a sequence of rules:(), [], (()), ([]), () [], () [()],{{}}And the following are not:(,[,],) (, ()), ([(), Now, give you some strings consisting of "("
Label: DP Dynamic Planning
Http://acm.nyist.net/JudgeOnline/problem.php? PID = 15
DP [I] [J] indicates the minimum number of parentheses to be added from I to J to meet the matching conditions.
Initialization:
If (I = J)
DP [I] [J] = 1;
Else
DP [I] [J] = inf;
Status transfer:
When I
If (MATCH (STR [I], STR [J]) DP [I] [J] = min (DP [I] [J], d [I + 1] [J-1]);
Then split the interval and find the optimal split point K. (I
DP [I] [J] = min (DP [I] [J], DP [I] [k] + dp [k + 1] [J]);
During the lo
‘{‘: - Case‘[‘: - Case‘(‘: +Chstack.push (CH);//if the first half of the parentheses are detected, the stack operation is performed - Break; + Case‘}‘: A Case‘]‘: at Case‘)‘: - if(!chstack.isempty ()) {//anti-parenthesis detected -chpop=Chstack.peek (); - if((' {' {' ==chpop '} '!=ch)//determine if the parentheses at the top of the stack match the current read -in parenthesis -|| (' [' ==chpop '] '! =ch) -|| (' (' ==chpop ') '! =c
in the company of a project, need to use the VS2013 Editor, after using the feeling a bit less cool. After the method is defined in the JS file, because the method is longer, after writing and then come back to see some inconvenient, especially in the method there are a few judgments, posterity again look at the time will be some not good analysis, fortunately, these years to cultivate up the spirit, found the VS2013 set braces, A method of highlighting such as parentheses. Open the vs2013→ too
Title Description:Define the valid parentheses sequence as follows:1 empty sequence is a valid sequence2 If S is a valid sequence, then (s) and [s] are also valid sequences3 If A and B are valid sequences, then AB is also a valid sequenceFor example: The following are the valid parentheses sequence(), [], (()), ([]), ()[], ()[()]The following are all illegal parenthesis sequences.(, [, ), ) (, ([)], ([(]Given a sequence consisting of ' (', ') ', ' [', ' and '] ', find the shortest legal sequence
Brace pairing problemTime limit:MS | Memory limit:65535 KB Difficulty:3
Describe
now, with a sequence of parentheses, you should check that the line brackets are paired.
Input
the first line enters a number n (0
Output
The
output of each set of input data is one row, if the parentheses contained in the string are paired, the output is yes, and if you do not pair the output no
Test instructions: give you a sequence of parentheses that asks you for the longest string length and number of matches.Solution: Stack Simulation + DPProblem Solving Code:1 //File name:5c.cpp2 //Author:darkdream3 //Created time:2015 March 09 Monday 12:00 57 seconds4 5#include 6#include 7#include 8#include Set>9#include Ten#include One#include A#include -#include -#include the#include -#include -#include -#include +#include -#include +#include A#include at#include - #defineLL Long
Ideas:Set a stack in the algorithm, each read into an empty numberOne: If the closing parenthesis: '} ') ' ' (Two cases):1: To the top of the stack of the most urgent expectations to be dissolved, the stack top elements need to stack;2: illegal situation, that is, the top of the stack of the most urgent expectations do not match, it needs to be (parentheses) stacked;Two: if the left parenthesis: ' (' { ') ' ['As a new and more pressing stack of anticipation;the code of the sequential stack is no
Topic:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()()"Translation:Give you an n, generate n set of parentheses, rules that conform to parenthesesIdeas:This problem before the data structure has been done, and the number of the stack is related.The name is called Cattleya number.Baidu Encyclopedia VikiAttach some Daniel's explanations about the number
Topic:Given A string containing just the characters‘(‘,‘)‘,‘{‘,‘}‘,‘[‘and‘]‘, determine if the input string is valid.The brackets must close in the correct order,"()"and"()[]{}"is all valid but"(]"and"([)]"is not.Translation:Give a string to determine if the parentheses match successfully.Ideas:With a word Fu Yi, read to a character when judged, if the top of the stack and the current character is satisfied with the left and right brackets matching, then pop, otherwise press the stack.If the las
Note: Empty line to output yes, to use get Read function, this problem let me learn to get and scanf function in addition to the space problem orhave a the difference between, scanf put the space, Tab, enter all as the end flag, will not be read into them, the back automatically add ' \ ', so space, enter, Tabare in buffer, which can be read with GetChar (), but the Get () function will also treat the carriage return as the end flag, but they will read theinto, read The string is ' GetChar ', so
. When the mold on the machine to see whether the mold number is the same as the scheduling, the wall thickness, length, color, order number mastery is conducive to improve production, control good quality.2, the host manual attention mattersA qualified host hand must have a tacit understanding with the monitor, can communicate with the monitor, clear Monitor production plan, monitor not in the field can command production, will not cause downtime. Only when the operator is familiar with the pro
two lines, the first line contains the original input characters, the second line is "$", "?" and spaces, "$" and "?" Indicates that the corresponding opening and closing parentheses do not match.Sample input(ABCD (x)) (Rttyy ()) SSS) (Sample output(ABCD (x)$$) (Rttyy ()) SSS) (? ?$
#include #include#include#includestring.h>using namespacestd;intMain () {inti; Charstr[101], mark[101]; while(SCANF ("%s", str)! =EOF) {StackChar>S; for(i =0; I ) { if(Str[i] = ='(') {s.push (i);
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.