class Solution {
public:
int cnt = 0;
int numberOfMatches(int n) {
// 偶数 / 2
// 奇数 产生 (n - 1) / 2 + 1 个队伍
if (n == 1) return cnt;
if (n % 2 == 0) {
cnt += n / 2;
n/=2;
}
else {
cnt += (n - 1 ) / 2 ;
n = (n - 1 ) / 2 + 1;;
}
return numberOfMatches(n);
}
};
class Solution {
public:
int minPartitions(string s) {
int len = s.length();
int ans = 0;
int max = 0;
int temp = 0;
while(1) {
int flag = 0;
for (int i = 0; i < len; i++) {
if (s[i] >= '1') {
s[i] = s[i] - 1;
flag = 1;
}
}
if (flag == 1) {
ans ++;
} else {
return ans;
}
}
}
};
class Solution {
public:
int stoneGameVII(vector<int>& w) {
int n = w.size();
vector<int> s(n + 1);
for (int i = 1; i <=n ; i++) s[i] = s[i - 1] + w[i - 1]; // 前缀和
vector<vector<int> > f(n + 1, vector<int>(n + 1));
for (int len = 2; len <= n; len ++) {
for (int i = 1; i + len - 1 <= n; i++) {
int j = i + len - 1;
f[i][j] = max(s[j] - s[i] - f[i + 1][j], s[j - 1] - s[i - 1] - f[i][j - 1]);
}
}
return f[1][n];
}
};
class Solution {
public:
int maxHeight(vector<vector<int>>& w) {
for (auto& x:w ) sort(x.begin(), x.end()); // 先旋转调整长宽高 保证高最大
sort(w.begin(), w.end(), greater<vector<int>>()); // 从大到小排序
int n = w.size();
vector<int> f(n); // 状态数组
int res = 0;
for (int i = 0; i < n; i++) {
f[i] = w[i][2];
for (int j = 0; j < i; j++) {
if (w[j][0] >= w[i][0] && w[j][1] >= w[i][1] && w[j][2] >= w[i][2]) {
f[i] = max(f[i], f[j] + w[i][2]);
}
}
res = max(res, f[i]);
}
return res;
}
};