调了2天了...还是WA75 求各位dalao帮忙debug下
查看原帖
调了2天了...还是WA75 求各位dalao帮忙debug下
24878
iodwad楼主2018/4/14 21:28
#include <iostream>
#include <cstdio>
#include <cstring>

const int MaxN = 10000 + 5;
const int MaxM = 1000 + 5;
const int Infinity = 0x3f3f3f3f;

int N, M, K, Ans;
int Dp[2][MaxM], X[MaxN], Y[MaxN];
bool Book[MaxN][MaxM];

inline int read()
{
    register int x = 0;
    register char ch = getchar();
    while(!isdigit(ch)) ch = getchar();
    while(isdigit(ch))
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x;
}

int main()
{
    //freopen("birda.in", "r", stdin);
    //freopen("birda.out", "w", stdout);
    bool flag;
    N = read();
    M = read();
    K = read();
    for(int i = 1; i <= N; ++i)
    {
        X[i] = read();
        Y[i] = read();
    }
    for(int i = 1; i <= K; ++i)
    {
        int x = read();
        int l = read();
        int h = read();
        for(int j = 1; j <= l; ++j) Book[x][j] = true;
        for(int j = h; j <= M; ++j) Book[x][j] = true;
    }
    for(int i = 1, o = 1; i <= N; ++i, o ^= 1)
    {
        flag = false;
        for(int j = 1; j <= M; ++j) Dp[o][j] = Infinity;
        for(int j = X[i] + 1; j <= M; ++j)
            if(!Book[i][j]) Dp[o][j] = std::min(Dp[o ^ 1][j - X[i]], Dp[o][j - X[i]]) + 1;
        if(!Book[i][M])
        {
            for(int j = 0; j <= X[i]; ++j)
                Dp[o][M] = std::min(Dp[o][M], std::min(Dp[o ^ 1][M - j], Dp[o][M - j]) + 1);
        }
        for(int j = 1; j <= M - Y[i]; ++j)
            if(!Book[i][j]) Dp[o][j] = std::min(Dp[o][j], Dp[o ^ 1][j + Y[i]]);
        for(int j = 1; j <= M; ++j)
        {
            if(Dp[o][j] < Infinity)
            {
                flag = true;
                break;
            }
        }
        if(!flag) break;
        if(Book[i][M]) ++Ans;
    }
    if(!flag) printf("0\n%d\n", Ans);
    else
    {
        Ans = Infinity;
        for(int i = 1; i <= M; ++i) Ans = std::min(Ans, Dp[N & 1][i]);
        printf("1\n%d\n", Ans);
    }
    return 0;
}
2018/4/14 21:28
加载中...