brackets

POJ 2955 Brackets 区间dp

心已入冬 提交于 2020-01-14 13:19:50
http://poj.org/problem?id=2955 区间dp的写法还是dfs的好写。 设dp[i][j]表示[i, j]这个区间的合法情况的最大值。 然后想要求[i, j]合法情况的最大值,有两种。 1、如果i和j的搭配的括号,那么dp[i][j] = dp[i + 1][j - 1] + 2; 2、同时还可能是分开区间,合并后才更大,例如:()() dp[i][j] = max(dp[i][j], dp[i][k] + dp[k + 1][j]); #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <assert.h> #define IOS ios::sync_with_stdio(false) using namespace std; #define inf (0x3f3f3f3f) typedef long long int LL; #include <iostream> #include <sstream> #include <vector> #include <set> #include <map> #include <queue> #include <string> #include <bitset>

Loading a JSON file containing JSON within brackets

流过昼夜 提交于 2020-01-14 10:23:54
问题 I'm trying to load a JSON file on a website using C# and JSON.Net However, I'm running into a problem when it runs because all the JSON is within []. Here's the JSON: [{"embed_count":"16","name":"live_user_catreina","stream_count":"133","category":"gaming","format":"live","channel_count":272,"title":"SWTOR - Sith Marauder - L42 - Belsavis - The Fatman","featured":true,"site_count":"117","abuse_reported":false,"channel":{"image_url_large":"http://static-cdn.jtvnw.net/jtv_user_pictures/catreina

POJ 2955 Brackets 区间dp

杀马特。学长 韩版系。学妹 提交于 2020-01-13 12:04:44
按照合法匹配条件,找最大的匹配 一眼就是区间dp 也知道dp[i][j]表示i-j中最大的匹配 但是状态转移方程怎么写呢?? 其实对于这个题,感觉有很多种写法,看过网上的各种各样的题解,强烈Orz~ 思路: 还是倒着dp,更新dp[i][j],有两种情况 1:当前字符不在最佳匹配中,dp[i][j]=dp[i+1][j]; 2:当前字符在最佳匹配中,dp[i][j]=max(dp[i][j],dp[i][k-1]+dp[k+1][j]+2),前提条件是i位置和k位置匹配成功 #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<cstdlib> #include<cmath> using namespace std; typedef long long LL; int dp[105][105]; char s[105]; int main() { while(~scanf("%s",s+1)) { if(s[1]=='e')break; int n=strlen(s+1); memset(dp,0,sizeof(dp)); for(int i=n-1;i>=1;--i) { for(int j=i+1;j<=n;++j) { dp[i][j]=dp[i+1][j];

match specific word between brackets

南楼画角 提交于 2020-01-07 08:33:10
问题 I need match and replace specific word between brackets (including the brackets). something like this: xxx(xxxxSPECIFICWORDxxxxxxxxxxx)xxx I need replace this: (xxxxSPECIFICWORDxxxxxxxxxxx) my text looks something like this: xx(xxxx)xxxx(xxxxxxxx)xxx(xxx)xxx(xxxxSPECIFICWORDxxxxxxxxxxx)xxx I tried write regex with preg_replace the problem that it replace all the text from the first bracket to my last specific word bracket. I realy don't know what to do can someone help me? thanks. 回答1: Dennis

match specific word between brackets

瘦欲@ 提交于 2020-01-07 08:32:06
问题 I need match and replace specific word between brackets (including the brackets). something like this: xxx(xxxxSPECIFICWORDxxxxxxxxxxx)xxx I need replace this: (xxxxSPECIFICWORDxxxxxxxxxxx) my text looks something like this: xx(xxxx)xxxx(xxxxxxxx)xxx(xxx)xxx(xxxxSPECIFICWORDxxxxxxxxxxx)xxx I tried write regex with preg_replace the problem that it replace all the text from the first bracket to my last specific word bracket. I realy don't know what to do can someone help me? thanks. 回答1: Dennis

Recursive regex in R for curly braces

南楼画角 提交于 2020-01-05 03:54:04
问题 I have some text string in the following pattern. x = "sdfwervd \calculus{fff}{\trt{sdfsdf} & \trt{sdfsdf} & \trt{sdfsdf} \\{} sdfsdf & sdfsdf & sefgse3 } aserdd wersdf sewtgdf" I want to use regex to capture the text "fff" in the string \calculus{fff} and replace it with something else. Further I want to capture the string between the first { after \calculus{.+} and it's corresponding closing curly brace } . How to do this with regex in R ? The following captures everything till last curly

VB Brackets in Enum?

和自甴很熟 提交于 2020-01-04 14:13:25
问题 I'm finding this in some legacy code and just curious what the brackets are for? Public Enum myEnum none = 0 abc = 2 def = 4 ghi= 6 [jkl] = 8 mno = 9 End Enum 回答1: They're not needed in the example you provided, which I assume you have obscured, but the brackets let you specify a name for an enum item that would otherwise conflict with a reserved word. 回答2: Brackets are usually used when you want to use a keyword for a variable, classname, function name, or something else where using a

How do I match a quoted string followed by a string in curly brackets?

元气小坏坏 提交于 2020-01-04 05:22:12
问题 I need a regex expression for matching a string in quotes and then a white space then a round bracket then a curly bracket. For example this is the text I want to match in Java: "'Allo 'Allo!" (1982) {A Barrel Full of Airmen (#7.7)} What would the regex for this be? Sorry, but I'm just really lost. I tried a lot of different things but now I'm so stumped. 回答1: "[^"]*"\s*\([^)]*\)\s*\{[^}]*\} 回答2: This should do it: Pattern p = Pattern.compile("\"(.*?)\"\\s+\\((\\d{4})\\)\\s+\\{(.*?)\\}");

LeetCode_301删除无效的括号

丶灬走出姿态 提交于 2020-01-03 09:04:25
删除最小数量的无效括号,使得输入的字符串有效,返回所有可能的结果。 说明: 输入可能包含了除 ( 和 ) 以外的字符。 class Solution { public List < String > removeInvalidParentheses ( String s ) { List < String > list = new ArrayList < String > ( ) ; if ( s == null ) return list ; if ( s . equals ( "" ) ) { list . add ( "" ) ; return list ; } //首先求出要去除左右括号的数目,采用提示中的方法 int left = 0 ; int right = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char ch = s . charAt ( i ) ; if ( ch == '(' ) { left ++ ; } else if ( ch == ')' ) { if ( left > 0 ) { left -- ; } else { right ++ ; } } } dfs ( s , 0 , left , right , "" , list ) ; return list ; } /* *

Syntax error on token “;”, { expected after this token in Random string creator

隐身守侯 提交于 2020-01-02 03:13:09
问题 I am writing code to generate a random 3 letter strings using the letters a, b, and c. I am getting the error message "Syntax error on token ";", { expected after this token" after the line where i create the random variable (Random rand = new Random();). I do not know why I am getting this error when it looks fine to me. I am also getting the error message: Syntax error, insert "}" to complete ClassBody, after the last bracket in the program. I am almost postive all my closing brackets match