mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-10-29 19:42:40 +00:00
Compare commits
2 Commits
efab9f4d2e
...
4ccd04aeb3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ccd04aeb3 | ||
|
|
25c16bcf5a |
168
src/10/4/P2540.cpp
Normal file
168
src/10/4/P2540.cpp
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int n;
|
||||||
|
int cnts[20];
|
||||||
|
int ans;
|
||||||
|
|
||||||
|
int to_rank(int a, int b) {
|
||||||
|
if (a == 0)
|
||||||
|
return 16 + b - 1;
|
||||||
|
if (a == 1)
|
||||||
|
return 14;
|
||||||
|
if (a == 2)
|
||||||
|
return 15;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dfs(int moves) {
|
||||||
|
if (moves >= ans) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bool empty = true;
|
||||||
|
for (int i = 3; i <= 17; ++i) {
|
||||||
|
if (cnts[i] > 0) {
|
||||||
|
empty = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty) {
|
||||||
|
ans = std::min(ans, moves);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int len = 12; len >= 5; --len) {
|
||||||
|
for (int i = 3; i <= 14 - len + 1; ++i) {
|
||||||
|
bool pos = true;
|
||||||
|
for (int k = i; k < i + len; ++k) {
|
||||||
|
if (cnts[k] == 0) {
|
||||||
|
pos = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (pos) {
|
||||||
|
for (int k = i; k < i + len; ++k)
|
||||||
|
cnts[k]--;
|
||||||
|
dfs(moves + 1);
|
||||||
|
for (int k = i; k < i + len; ++k)
|
||||||
|
cnts[k]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int len = 10; len >= 3; --len) {
|
||||||
|
for (int i = 3; i <= 14 - len + 1; ++i) {
|
||||||
|
bool pos = true;
|
||||||
|
for (int k = i; k < i + len; ++k) {
|
||||||
|
if (cnts[k] < 2) {
|
||||||
|
pos = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (pos) {
|
||||||
|
for (int k = i; k < i + len; ++k)
|
||||||
|
cnts[k] -= 2;
|
||||||
|
dfs(moves + 1);
|
||||||
|
for (int k = i; k < i + len; ++k)
|
||||||
|
cnts[k] += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int len = 6; len >= 2; --len) {
|
||||||
|
for (int i = 3; i <= 14 - len + 1; ++i) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 3; i <= 15; ++i) {
|
||||||
|
if (cnts[i] >= 3) {
|
||||||
|
for (int k = 3; k <= 17; ++k) {
|
||||||
|
if (k != i && cnts[k] >= 1) {
|
||||||
|
cnts[i] -= 3;
|
||||||
|
cnts[k] -= 1;
|
||||||
|
dfs(moves + 1);
|
||||||
|
cnts[i] += 3;
|
||||||
|
cnts[k] += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cnts[i] >= 3) {
|
||||||
|
for (int k = 3; k <= 15; ++k) {
|
||||||
|
if (k != i && cnts[k] >= 2) {
|
||||||
|
cnts[i] -= 3;
|
||||||
|
cnts[k] -= 2;
|
||||||
|
dfs(moves + 1);
|
||||||
|
cnts[i] += 3;
|
||||||
|
cnts[k] += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cnts[i] >= 4) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cnts[i] >= 4) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cnts[16] > 0 && cnts[17] > 0) {
|
||||||
|
cnts[16]--;
|
||||||
|
cnts[17]--;
|
||||||
|
dfs(moves + 1);
|
||||||
|
cnts[16]++;
|
||||||
|
cnts[17]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 3; i <= 17; ++i) {
|
||||||
|
if (cnts[i] >= 4) {
|
||||||
|
cnts[i] -= 4;
|
||||||
|
dfs(moves + 1);
|
||||||
|
cnts[i] += 4;
|
||||||
|
}
|
||||||
|
if (cnts[i] >= 3) {
|
||||||
|
cnts[i] -= 3;
|
||||||
|
dfs(moves + 1);
|
||||||
|
cnts[i] += 3;
|
||||||
|
}
|
||||||
|
if (cnts[i] >= 2) {
|
||||||
|
cnts[i] -= 2;
|
||||||
|
dfs(moves + 1);
|
||||||
|
cnts[i] += 2;
|
||||||
|
}
|
||||||
|
if (cnts[i] >= 1) {
|
||||||
|
cnts[i] -= 1;
|
||||||
|
dfs(moves + 1);
|
||||||
|
cnts[i] += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
std::cin >> n;
|
||||||
|
memset(cnts, 0, sizeof(cnts));
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
|
int a, b;
|
||||||
|
std::cin >> a >> b;
|
||||||
|
cnts[to_rank(a, b)]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
ans = n;
|
||||||
|
dfs(0);
|
||||||
|
std::cout << ans << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios_base::sync_with_stdio(false);
|
||||||
|
std::cin.tie(NULL);
|
||||||
|
int T;
|
||||||
|
std::cin >> T >> n;
|
||||||
|
while (T--) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO to done
|
||||||
3
src/10/4/P3959.cpp
Normal file
3
src/10/4/P3959.cpp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
int main(){
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user