The method is applying DFS.

```
class Solution {
public:
int cnt;
bool makesquare(vector<int>& nums) {
if (!nums.size()) return false;
sort(nums.begin(), nums.end());
reverse(nums.begin(), nums.end());
int sum = 0;
for (int n : nums) sum += n;
if (sum % 4) return false;
int target = sum / 4;
cnt = 0;
for (int i = 0; i < 4; i++) {
vector<int> path;
if (!dfs(nums, target, 0, path)) return false;
for (int j = path.size()-1; j >= 0; j--) {
nums.erase(nums.begin()+path[j]);
}
}
return true;
}
bool dfs(vector<int>& nums, int target, int start, vector<int>& path) {
if (target == 0) {
return true;
}
for (int i = start; i < nums.size(); i++) {
if (nums[i] > target) continue;
path.push_back(i);
if (dfs(nums, target-nums[i], i+1, path)) return true;
path.pop_back();
}
return false;
}
};
```