社区讨论
除#1 #2 外全部WA,20 pts状压求调
P2704[NOI2001] 炮兵阵地参与者 1已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @lo170hmb
- 此快照首次捕获于
- 2023/10/22 16:14 2 年前
- 此快照最后确认于
- 2023/11/02 15:51 2 年前
CPP
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long LL;
const int N = 103, M = 10, S = 1 << M;
int n, m, g[N], cnt[S];
vector<int> states;
vector<int> head[S];
LL f[2][S][S];
int main() {
cin >> n >> m;
for(int i = 1; i <= n; i ++)
for(int j = 0; j < m; j ++) {
char c; cin >> c;
if(c == 'H') g[i] += 1 << j;
}
for(int s = 0; s < (1 << m); s ++)
if(!(s & s >> 1 || s & s >> 2)) {
states.push_back(s);
int s_ = s, tot = 0;
while(s_) tot += s_ & 1, s_ >>= 1;
cnt[s] = tot;
}
for(int i = 0; i < (int)states.size(); i ++)
for(int j = 0; j < (int)states.size(); j ++) {
int s1 = states[i], s2 = states[j];
if(!(s1 & s2)) head[s1].push_back(s2);
}
for(int i = 1; i <= n + 2; i ++)
for(int a = 0; a < (int)states.size(); a ++) {
int s1 = states[a];
if(!(g[i] & s1)) {
for(int b = 0; b < (int)head[s1].size(); b ++) {
int s2 = states[b];
for(int c = 0; c < (int)head[s2].size(); c ++) {
int s3 = states[c];
if(!(s1 & s3))
f[i & 1][s1][s2] = max(f[i & 1][s1][s2], f[(i - 1) & 1][s2][s3] + cnt[s1]);
}
}
}
}
cout << f[(n + 2) & 1][0][0];
return 0;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...