zoukankan      html  css  js  c++  java
  • luogu_P1941 飞扬的小鸟

    注意完全背包的意义!!!

    前边状态不一定要合法!

    整个s9决赛夜都在调nmdp

    //#pragma GCC optimize("Ofast")
    
    #include<iostream>
    #include<cstdio>
    
    #define ri register int
    #define u int
    
    namespace opt {
    
        inline u in() {
            u x(0),f(1);
            char s(getchar());
            while(s<'0'||s>'9') {
                if(s=='-') f=-1;
                s=getchar();
            }
            while(s>='0'&&s<='9') {
                x=(x<<1)+(x<<3)+s-'0';
                s=getchar();
            }
            return x*f;
        }
    
    }
    
    using opt::in;
    
    #include<algorithm>
    #include<cstring>
    
    #define NN 10005
    
    namespace mainstay {
    
        u N,M,K,up[NN],vt[NN],sum[NN],down[NN],f[2][1005];
    
        struct node {
            u x,l,h;
        } a[NN];
    
        inline bool cmp(const node &x,const node &y) {
            return x.x<y.x;
        }
    
        inline void solve() {
            N=in(),M=in(),K=in(),a[1].x=-1;
            for(ri i(0); i<N; ++i) up[i]=in(),down[i]=in();
            for(ri i(1); i<=K; ++i) a[i].x=in(),a[i].l=in(),a[i].h=in(),vt[a[i].x]=1;
            std::sort(a+1,a+K+1,cmp);
            for(ri i(1); i<=N; ++i) sum[i]=sum[i-1]+(vt[i]!=0);
            u mx(0),cnt(1),l,r;
            for(ri i(1); i<=N; ++i) {
                u now(i&1),pre(now^1);
                std::memset(f[now],0x3f,sizeof(f[now]));
                l=1,r=M;
                if(a[cnt].x==i) l=a[cnt].l+1,r=a[cnt].h-1,++cnt;
                for(ri j(1);j<=r;++j) {
                    if(j-up[i-1]>0){
                        f[now][j]=std::min(f[pre][j-up[i-1]],f[now][j-up[i-1]])+1;
                    }
                } 
                if(r==M){
                    for(ri j(M-up[i-1]+1);j<=M;++j) 
                    f[now][M]=std::min(f[now][M],std::min(f[now][j],f[pre][j])+1);
                }
                for(ri j(1);j<l;++j) f[now][j]=0x3f3f3f3f;
                for(ri j(l);j<=r;++j){
                    if(j+down[i-1]<=M)
                    f[now][j]=std::min(f[now][j],f[pre][j+down[i-1]]);
                }
                for(ri j(1);j<=M;++j) if(f[now][j]<0x3f3f3f3f) mx=i;
            }
            u ans(0x3f3f3f3f);
            l=1,r=M;
            if(a[K].x==N) l=a[K].l+1,r=a[K].h-1;
            for(ri i(l); i<=r; ++i) ans=std::min(f[N&1][i],ans);
            if(ans^0x3f3f3f3f) printf("1
    %d",ans);
            else printf("0
    %d",sum[mx]);
        }
    
    }
    
    int main() {
    
        //freopen("x.txt","r",stdin);
        std::ios::sync_with_stdio(false);
        mainstay::solve();
    
    }
  • 相关阅读:
    (CodeForces 548B 暴力) Mike and Fun
    (BestCoder Round #64 (div.2))Array
    (2015 杭电校赛 )玩骰子
    js基础
    frame框架标签
    html
    div嵌套div标签 里层的div透明属性
    div嵌套div标签
    盒子标签div嵌套
    divspan盒子模型
  • 原文地址:https://www.cnblogs.com/ling-zhi/p/11831948.html
Copyright © 2011-2022 走看看