标签:
#include <bits/stdc++.h>
using namespace std;
class Cut {
public:
int getMaximum(vector <int> eelLengths, int maxCuts) {
sort(eelLengths.begin(), eelLengths.end());
int n = eelLengths.size();
int ans = 0;
for (int i = 0; i < n; ++i) {
if (eelLengths[i] % 10 == 0) {
int t = min(eelLengths[i] / 10 - 1, maxCuts);
if ((t + 1) * 10 != eelLengths[i]) --ans;
ans += t + 1;
maxCuts -= t;
}
}
for (int i = 0; i < n; ++i) {
if (eelLengths[i] % 10 != 0) {
if (maxCuts > 0) {
int t = min(eelLengths[i] / 10, maxCuts);
ans += t;
maxCuts -= t;
}
}
}
return ans;
}
};
#include <bits/stdc++.h>//枚举+dp
using namespace std;
long long f[21][21];
class SPartition {
public:
long long getCount(string s) {
int n = s.size();
int tx = 0, to = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == ‘x‘) ++tx;
else ++to;
}
if ((tx & 1) || (to & 1)) return 0;
long long ans = 0;
for (int i = 0; i < (1 << (n / 2)); ++i) {
memset(f, 0, sizeof(f));
f[0][0] = 1;
if (__builtin_popcount(i) != tx / 2) continue;
for (int j = 0; j < n; ++j) {
for (int k = 0; k <= min(n / 2, j); ++k)
if (s[j] == ‘x‘) {
if (f[k][j - k]){
if (k != n / 2 && (i >> k & 1)) f[k + 1][j - k] += f[k][j - k];
if (j - k != n / 2 && (i >> (j - k) & 1)) f[k][j - k + 1] += f[k][j - k];
}
}
else {
if (f[k][j - k]) {
if (k != n / 2 && !(i >> k & 1)) f[k + 1][j - k] += f[k][j - k];
if (j - k != n / 2 && !(i >> (j - k) & 1)) f[k][j - k + 1] += f[k][j - k];
}
}
}
ans += f[n / 2][n / 2];
}
return ans;
}
};
标签:
原文地址:http://blog.csdn.net/mlzmlz95/article/details/46127509