先用dfs搜索所有的情况,然后判断每种情况是不是括号匹配

#include <vector>
#include <string>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <queue> using namespace std; class BracketExpressions
{
public:
string src,dst;
const string bracket="()[]{}"; bool check(string& str){
stack<char> st;
for(int i = ; i < str.length(); ++ i){
if(st.empty()) st.push(str[i]);
else{
char ch = st.top();
if((str[i]==']'&& ch=='[')||(str[i] == '}' && ch=='{') || (str[i]==')'&& ch=='(')) st.top();
else st.push(str[i]);
}
}
cout<<st.size()<<endl;
return st.empty()?true:false;
} bool dfs(int cur){
if(cur==src.length()) return check(dst);
if(src[cur]=='X'){
bool flag = false;
for(int i = ; i < bracket.length();++i){
dst[cur]=bracket[i];
flag|=dfs(cur+);
}
return flag;
}else return dfs(cur+);
} string ifPossible(string expression)
{
src=dst=expression;
return dfs()?"possible":"impossible";
} }; // Powered by FileEdit
// Powered by TZTester 1.01 [25-Feb-2003]
// Powered by CodeProcessor // Powered by FileEdit
// Powered by TZTester 1.01 [25-Feb-2003]
// Powered by CodeProcessor

topcoder SRM 628 DIV2 BracketExpressions的更多相关文章

  1. topcoder srm 628 div2 250 500

    做了一道题,对了,但是还是掉分了. 第二道题也做了,但是没有交上,不知道对错. 后来交上以后发现少判断了一个条件,改过之后就对了. 第一道题爆搜的,有点麻烦了,其实几行代码就行. 250贴代码: #i ...

  2. topcoder SRM 628 DIV2 BishopMove

    题目比较简单. 注意看测试用例2,给的提示 Please note that this is the largest possible return value: whenever there is ...

  3. Topcoder Srm 673 Div2 1000 BearPermutations2

    \(>Topcoder \space Srm \space 673 \space Div2 \space 1000 \space BearPermutations2<\) 题目大意 : 对 ...

  4. Topcoder Srm 671 Div2 1000 BearDestroysDiv2

    \(>Topcoder \space Srm \space 671 \space Div2 \space 1000 \space BearDestroysDiv2<\) 题目大意 : 有一 ...

  5. 求拓扑排序的数量,例题 topcoder srm 654 div2 500

    周赛时遇到的一道比较有意思的题目: Problem Statement      There are N rooms in Maki's new house. The rooms are number ...

  6. Topcoder srm 632 div2

    脑洞太大,简单东西就是想复杂,活该一直DIV2; A:水,基本判断A[I]<=A[I-1],ANS++; B:不知道别人怎么做的,我的是100*N*N;没办法想的太多了,忘记是连续的数列 我们枚 ...

  7. Topcoder SRM 628 DIV 2

    被自己蠢哭了.... 250-point problem 国际象棋棋盘上给出两个坐标,问象从一个走到还有一个最少要几步. 黑格象仅仅能走黑格,白格象仅仅能走白格,仅仅要推断两个坐标的颜色是否同样就能推 ...

  8. SRM 628 DIV2

    250  想想就发现规律了. 500  暴力,括号匹配. 1000 给一个f数组,如果i存在,那么f[i]也得存在,问这样的集合有多少种. 先拓扑一下,dp[i] = mul(dp[son]+1)最后 ...

  9. Topcoder SRM 683 Div2 B

    贪心的题,从左向右推过去即可 #include <vector> #include <list> #include <map> #include <set&g ...

随机推荐

  1. json和jsonp

    JSON是一种数据交换格式!   JSONP是一种依靠开发人员的聪明才智创造出的一种非官方跨域数据交互协议!   一般使用JSON来传数据,靠JSONP来跨域.   JSON的优点: 1.基于纯文本, ...

  2. testng 失败自动截图

    testng执行case failed ,testng Listener会捕获执行失败,如果要实现失败自动截图,需要重写Listener的onTestFailure方法 那么首先新建一个Listene ...

  3. 关于mysql数据库的备份和还原

    在搭建网站的过程中常遇到文件的备份与还原,以备下次再使用 备份: 图中蓝色画线处为备份命令,wordpress为要备份的数据库名,.">"可将结果输出到文件中,/opt/wo ...

  4. SemanticZoom配合GridView组件的使用关键点

    1,SemanticZoom 有两个重要属性 默认值ZoomedInView(不设置的话,默认显示,包括分类名和分类成员)和ZoomedOutView(这个是缩小后的目录,只要包括分类名,点击跳到对应 ...

  5. Android源码阅读 – Zygote

    @Dlive 本文档: 使用的Android源码版本为:Android-4.4.3_r1 kitkat (源码下载: http://source.android.com/source/index.ht ...

  6. Python之路,Day7 - Python基础7 面向对象

    本节内容:   面向对象编程介绍 为什么要用面向对象进行开发? 面向对象的特性:封装.继承.多态 类.方法.     引子 你现在是一家游戏公司的开发人员,现在需要你开发一款叫做<人狗大战> ...

  7. codeforces 484D Kindergarten (dp、贪心)

    题意:给n个数,分成若干个连续组,每组获益为max-min,输出最大获益. 参考:http://blog.csdn.net/keshuai19940722/article/details/408735 ...

  8. dom4j使用总结

    1.加载Xml 从文件加载 SAXReader reader = new SAXReader(); String filePath = "/xmlfile/" + fileName ...

  9. 将数据导入Excel

    /** * 查询未打印订单 * @param req * @param sort * @param order * @param rows * @param page * @return */ pub ...

  10. mysql 5.7.14 免安装配置方法教程

    仅供参考 一.下载 1. 进入mysql官网,下载Mysql-5.7.14,下载地址:http://dev.mysql.com/downloads/mysql/ 2.将下载好的文件解压到自定义目录 二 ...