Paste: 2178
Author: | cai ji |
Mode: | c++ |
Date: | Thu, 12 May 2022 01:07:36 |
Plain Text |
typedef long long ll;
class Solution {
private:
vector<ll> res;
public:
vector<long long> maximumEvenSplit(long long finalSum) {
vector<ll> tmp;
if (finalSum % 2 != 0)
return {};
dfs(tmp, finalSum, finalSum, 2);
return res;
}
bool dfs(vector<ll>& tmp, ll curr, ll finalSum, ll begin) {
if (!curr) {
if (!res.size()) {
res = tmp;
}
return true;
}
if (curr < 0)
return false;
for (ll i = begin; i <= finalSum; i += 2) {
tmp.push_back(i);
curr -= i;
if (dfs(tmp, curr, finalSum, i + 2))
return true;
curr += i;
tmp.pop_back();
}
return false;
}
};
New Annotation