题解 | #数位染色#
数位染色
http://www.nowcoder.com/practice/adf828f399de4932955734a4eac12757
#include<iostream>
using namespace std;
bool ans = false;
void dfs(string num,int temp,int val)
{
if(temp >= val){
if(temp == val){
ans = true;
return;
}
else
return;
}
else if(num.size()){
dfs(num.substr(1),temp + num[0] - '0',val);
dfs(num.substr(1),temp,val);
}
else
return;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
string num;
cin >> num;
int val = 0;
for(int i = 0;i < num.size();++i)
val += num[i] - '0';
if(val % 2 == 0)
dfs(num,0,val / 2);
if(ans)
cout << "Yes";
else
cout << "No";
}