记录编号 360236 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 [NOIP 2014]飞扬的小鸟 最终得分 100
用户昵称 Gravatarsxysxy 是否通过 通过
代码语言 C++ 运行时间 0.985 s
提交时间 2016-12-28 08:31:25 内存使用 39.59 MiB
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <cstdarg>
#include <list>
#include <queue>
#include <vector>
using namespace std;
#define MAXN 10006
int up[MAXN], down[MAXN];
int P[MAXN], L[MAXN], H[MAXN];
int f[10111][1014];
int inf = 168430090;
int main()
{
    freopen("birda.in", "r", stdin);
    freopen("birda.out", "w", stdout);
    int n, m, k;
    scanf("%d %d %d", &n, &m, &k);
    memset(f, 10, sizeof(f));
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", up+i-1);
        scanf("%d", down+i-1);
        L[i] = 0, H[i] = m+1; //,没有水管可以当作L = 0, H = m+1
    }
    for(int i = 1; i <= k; i++)
    {
        int p;scanf("%d", &p);
        scanf("%d", L+p);
        scanf("%d", H+p);
    }
    f[0][0] = inf;
    for(int i = 1; i <= m; i++)f[0][i] = 0;
    for(int i = 1; i <= n; i++)
    {
        for(int j = up[i-1]; j <= m; j++)
        {
            f[i][j] = min(f[i][j], f[i][j-up[i-1]]+1);
            f[i][j] = min(f[i][j], f[i-1][j-up[i-1]]+1);
        }
        for(int j = m-up[i-1]; j <= m; j++)
        {
            f[i][m] = min(f[i][m], f[i][j]+1);
            f[i][m] = min(f[i][m], f[i-1][j]+1);
        }
        for(int j = L[i]+1; j <= H[i]-1; j++)
        {
            if(j+down[i-1] <= m)
                f[i][j] = min(f[i][j], f[i-1][j+down[i-1]]);
        }
        for(int j = 1; j <= L[i]; j++)f[i][j] = inf; // not reachable;
        for(int j = H[i]; j <= m; j++)f[i][j] = inf;
    }
    int t = k, ans = inf;
    for(int i = n; i; i--)
    {
        for(int j = L[i]+1; j < H[i]; j++)ans = min(f[i][j], ans);
        if(ans != inf)break;
        if(H[i] <= m)t--;
    }
    if(t == k)printf("%d\n%d\n", 1, ans);
    else printf("%d\n%d\n", 0, t);
    return 0;
}