-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlack_IOI2000.cpp
More file actions
64 lines (52 loc) · 1.26 KB
/
Black_IOI2000.cpp
File metadata and controls
64 lines (52 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
#define MAX 105
const int INF = (1<<29);
int n, K;
int val[3][MAX], f[3][MAX];
int dp[12][MAX][5];
int result;
inline int min(int a, int b) {
return a < b ? a : b;
}
int getLoss(int i, int j) //0:上下不用, 1:上用, 2:下用, 3:灭火器覆盖最少1个小矩形, 4:覆盖至少2个矩形
{
if(j == 0) return f[1][i]+f[2][i];
else if(j == 1) return val[1][i]+f[2][i];
else if(j == 2) return val[2][i]+f[1][i];
else return val[1][i]+val[2][i];
}
int DP(int k, int i, int j) {
if(dp[k][i][j] != -1) return dp[k][i][j];
if(i == n) return 0;
int ans = INF, temp;
int nextk;
for(int p = 0; p <= 3; ++p) {
if(p == 3 && (j == 1 || j == 2 || j == 4)) p = 4;
if( p == 0 || j == p || j == 4 ) nextk = k;
else nextk = k+1;
if(nextk <= K) temp = DP(nextk, i+1, p)+getLoss(i+1, p);
else continue;
ans = min(ans, temp);
}
return dp[k][i][j] = ans;
}
int main() {
int i, j;
while( scanf("%d %d", &n, &K) != EOF ) {
for(i = 1; i <= 2; ++i) {
for(j = 1; j <= n; ++j)
scanf("%d", &val[i][j]);
}
for(i = 1; i <= 2; ++i) {
for(j = 1; j <= n; ++j)
scanf("%d", &f[i][j]);
}
memset(dp, -1, sizeof(dp));
result = DP(0, 0, 0);
printf("%d\n", result);
}
return 0;
}