题目链接:http://acm.sdibt.edu.cn:8080/judge/contest/view.action?cid=389#problem/A

简单的递归求解,不解释了!!

code:

#include <iostream>
#include <string>
using namespace std;
int flag=0,sum;
int search(int sum0)
{
char c_char;
int nod_number,L=0,r=0;
cin>>c_char;

if(!((cin>>nod_number)==0))
{
sum0+=nod_number;
L=search(sum0);
r=search(sum0);
}
else
{
cin.clear();
cin>>c_char;
return 1;
}
if((L==1&&r==1)&&sum0==sum)
flag=1;
cin.clear();
cin>>c_char;
}
int main()
{
int a;
while(cin>>sum)
{
flag=0;
a=search(0);
if(flag==1)
cout<<“yes”<<endl;
else
cout<<“no”<<endl;
}
return 0;
}

发表评论

电子邮件地址不会被公开。

Post Navigation