mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 18:52:02 +00:00
P1622 释放囚犯
R72788347
This commit is contained in:
parent
d9b8637917
commit
73b26e3a99
35
Luogu/P1622/P1622.cpp
Normal file
35
Luogu/P1622/P1622.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 1005;
|
||||
|
||||
int p, q, a[N], f[N][N];
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
|
||||
cin >> p >> q;
|
||||
for (int i = 1; i <= q; i++) {
|
||||
cin >> a[i];
|
||||
}
|
||||
|
||||
std::sort(a + 1, a + 1 + q);
|
||||
a[q + 1] = p + 1;
|
||||
for (int l = 1; l <= q; l++) {
|
||||
for (int i = 1, j = i + l - 1; j <= q; i++, j++) {
|
||||
f[i][j] = std::numeric_limits<int>::max();
|
||||
for (int k = i; k <= j; k++) {
|
||||
f[i][j] = std::min(f[i][j], f[i][k - 1] + f[k + 1][j] + a[j + 1] - a[i - 1] - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << f[1][q] << endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user