mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-08-31 23:41:41 +00:00
Compare commits
3 Commits
522e869e7b
...
8b1f7317ff
Author | SHA1 | Date | |
---|---|---|---|
8b1f7317ff | |||
84436ffbbe | |||
000e34da46 |
81
src/8/31/P2704.cpp
Normal file
81
src/8/31/P2704.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
static inline constexpr int popcount(int x) {
|
||||
return __builtin_popcount(x);
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios_base::sync_with_stdio(false);
|
||||
std::cin.tie(NULL);
|
||||
|
||||
int n, m;
|
||||
std::cin >> n >> m;
|
||||
|
||||
std::vector<int> map(n + 1, 0);
|
||||
for (int i = 1; i <= n; ++i) {
|
||||
std::string row;
|
||||
std::cin >> row;
|
||||
for (int j = 0; j < m; ++j) {
|
||||
if (row[j] == 'H') {
|
||||
map[i] |= (1 << j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<int> states;
|
||||
std::vector<int> counts;
|
||||
for (int i = 0; i < (1 << m); ++i) {
|
||||
|
||||
if (!((i << 1) & i) && !((i << 2) & i)) {
|
||||
states.push_back(i);
|
||||
counts.push_back(popcount(i));
|
||||
}
|
||||
}
|
||||
int num = states.size();
|
||||
|
||||
std::vector<std::vector<std::vector<int>>> dp(n + 1, std::vector<std::vector<int>>(num, std::vector<int>(num, 0)));
|
||||
|
||||
for (int i = 1; i <= n; ++i) {
|
||||
|
||||
for (int j = 0; j < num; ++j) {
|
||||
int si = states[j];
|
||||
|
||||
if (si & map[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int k = 0; k < num; ++k) {
|
||||
int sim1 = states[k];
|
||||
|
||||
if (si & sim1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int l = 0; l < num; ++l) {
|
||||
int sim2 = states[l];
|
||||
|
||||
if ((si & sim2) || (sim1 & sim2)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
dp[i][j][k] = std::max(dp[i][j][k], dp[i - 1][k][l] + counts[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ans = 0;
|
||||
for (int j = 0; j < num; ++j) {
|
||||
for (int k = 0; k < num; ++k) {
|
||||
ans = std::max(ans, dp[n][j][k]);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << ans << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
14
src/test.cpp
14
src/test.cpp
@ -1,10 +1,8 @@
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main(){
|
||||
int a=0;
|
||||
char* c = (char*)&a;
|
||||
c[0]=0x1f;
|
||||
c[1]=0x1f;
|
||||
c[2]=0x1f;
|
||||
c[3]=0x1f;
|
||||
printf("%d\n",a);
|
||||
int a = 1;
|
||||
a<<=32;
|
||||
cout<<a<<"\n";
|
||||
}
|
Loading…
Reference in New Issue
Block a user