FOJ2030(DFS:括号匹配)

View Code
#include < iostream >
using namespace std;
char ch[ 101 ];
int mark = 0 , cnt;
int len;
void dfs( int x , int y , int i )
{
if ( x < y )
{
return ; }
if ( y == x && i == len )
{
cnt
++ ;
}

if (ch[i] == ' ? ' )
{
dfs(x
+ 1 , y , i + 1 );
dfs(x, y
+ 1 , i + 1 );
}

if (ch[i] == ' ( ' )
{

dfs( x
+ 1 , y , i + 1 );

}

if (ch[i] == ' ) ' )
{
dfs( x , y
+ 1 , i + 1 );
}

}
int main()
{
while (cin >> ch)
{
cnt
= 0 ; len = strlen( ch );
dfs(
0 , 0 , 0 );

if (mark == 1 ) cout << " 0 " << endl;

else cout << cnt << endl;
}
return 0 ;

}

转载于:https://www.cnblogs.com/FCWORLD/archive/2011/05/17/2049261.html

评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符 “速评一下”
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页