# Luogu1941 飞扬的小鸟

代码：

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cstdio>
#include <cmath>
using namespace std;

const int MAX_N = 10005, MAX_M = 1005;

int n, m, k, max_dst;
int x[MAX_N], y[MAX_N], pos[MAX_N], pre_sum[MAX_N];
int bot[MAX_N], top[MAX_N], f[MAX_N][MAX_M];
bool has_stk[MAX_N];

int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= n; ++i) scanf("%d%d", &x[i], &y[i]);
for (int i = 1; i <= k; ++i) {
scanf("%d", &pos[i]);
scanf("%d%d", &bot[pos[i]], &top[pos[i]]);
has_stk[pos[i]] = true;
}
for (int i = 1; i < n; ++i) pre_sum[i] = pre_sum[i - 1] + has_stk[i];
memset(f, 0x3f, sizeof(f));
for (int i = 1; i <= m; ++i) f[0][i] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = x[i] + 1; j <= m; ++j) {
max_dst = (f[i][j] < 0x3f3f3f3f) ? i : max_dst;
f[i][j] = min(f[i][j], min(f[i - 1][j - x[i]], f[i][j - x[i]]) + 1);
}
for (int j = m - x[i]; j <= m; ++j) {
max_dst = (f[i][j] < 0x3f3f3f3f) ? i : max_dst;
f[i][m] = min(f[i][m], min(f[i - 1][j], f[i][j]) + 1);
}
for (int j = 1; j <= m - y[i]; ++j) {
max_dst = (f[i][j] < 0x3f3f3f3f) ? i : max_dst;
f[i][j] = min(f[i][j], f[i - 1][j + y[i]]);
}
if (has_stk[i]) {
for (int j = 1; j <= bot[i]; ++j) f[i][j] = 0x3f3f3f3f;
for (int j = top[i]; j <= m; ++j) f[i][j] = 0x3f3f3f3f;
}
}
register int min_res = 0x3f3f3f3f;
if (!has_stk[n]) {
for (int i = 1; i <= m; ++i) if (f[n][i] < 0x3f3f3f3f) {
max_dst = n;
min_res = min(min_res, f[n][i]);
}
} else {
for (int i = bot[n] + 1; i < top[n]; ++i) if (f[n][i] < 0x3f3f3f3f) {
max_dst = n;
min_res = min(min_res, f[n][i]);
}
}
if (max_dst == n) {
puts("1");
printf("%d", min_res);
} else {
printf("0\n%d", pre_sum[max_dst] - has_stk[max_dst]);
}
return 0;
}


posted @ 2018-11-05 12:50  AWordThatWeDefine  阅读(89)  评论(0编辑  收藏  举报