标签:
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define F first
#define S second
vector<pair<int, int> > a;
int b[55];
class DengklekMakingChains {
public:
int maxBeauty(vector <string> chains) {
int n = chains.size();
int ans = 0;
for (int i = 0; i < n; ++i) {
int t = 0, t1 = 0, t2 = 0;
bool f = 1;
for (int j = 0; j < chains[i].size(); ++j) {
if (chains[i][j] >= ‘0‘ && chains[i][j] <= ‘9‘) t += chains[i][j] - ‘0‘;
if (chains[i][j] == ‘.‘) {
f = 0;
if (!t1) t1 = t;
b[i] = max(b[i], t);
t = 0;
}
}
if (f) ans += t;
else {
if (chains[i][0] == ‘.‘) t1 = 0;
b[i] = max(b[i], t);
t2 = t, a.pb(mp(t1, t2));
}
}
n = a.size();
int t = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i == j) continue;
t = max(t, a[i].S + a[j].F);
}
t = max(t, a[i].S);
t = max(t, a[i].F);
}
ans += t;
n = chains.size();
for (int i = 0; i < n; ++i) ans = max(ans, b[i]);
return ans;
}
};
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 31, MOD = 1e9 + 7;
int n, m, k, f[N][N][9][(1 << 9) + 1];
class DengklekBuildingRoads {
public:
int numWays(int N, int M, int K) {
f[0][0][0][0] = 1;
for (int i = 1; i <= N; ++i)
for (int j = 0; j <= M; ++j) {
for (int mask = 0; mask < 1 << (K + 1); ++mask)
if (!(mask >> K & 1)) f[i][j][K][mask] = f[i - 1][j][0][mask << 1];
for (int k = K - 1; k >= 0; --k) {
for (int mask = 0; mask < 1 << (K + 1); ++mask) {
f[i][j][k][mask] = f[i][j][k + 1][mask];
if (i + k + 1 <= N && j) (f[i][j][k][mask] += f[i][j - 1][k][mask ^ ((1 << (k + 1)) | 1)]) %= MOD;
}
}
}
return f[N][M][0][0];
}
};
标签:
原文地址:http://blog.csdn.net/mlzmlz95/article/details/46378321