Skip to content

Instantly share code, notes, and snippets.

@nobodyzxc
Last active March 6, 2020 08:51
Show Gist options
  • Save nobodyzxc/1463033d9a63f91053bec0194f79ef31 to your computer and use it in GitHub Desktop.
Save nobodyzxc/1463033d9a63f91053bec0194f79ef31 to your computer and use it in GitHub Desktop.
#include<cstdio>
#define LL long long
bool go_tree(LL tar, LL cur, bool &isNIL){
LL val;
bool res = false, ll = false, rl = false;
if(scanf("\n(%lld", &val)){
res |= go_tree(tar, cur + val, ll);
res |= go_tree(tar, cur + val, rl);
res |= (ll && rl && tar == cur + val);
}
else isNIL = true;
scanf("\n)");
return res;
}
int main(){
bool _;
LL target;
while(~scanf("%lld", &target))
puts(go_tree(target, 0, _) ? "yes" : "no");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment