zoukankan      html  css  js  c++  java
  • poj 2392 建塔(多重背包+不定上界)

    http://blog.csdn.net/libin56842/article/details/9492351

    这次比较理解那个!dp[j]是为了什么,因为是滚动数组,没有这个的话used那边会出问题

    #include <iostream>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <cctype>
    #include <vector>
    #include <iterator>
    #include <set>
    #include <map>
    #include <sstream>
    using namespace std;
    
    #define mem(a,b) memset(a,b,sizeof(a))
    #define pf printf
    #define sf scanf
    #define spf sprintf
    #define pb push_back
    #define debug printf("!
    ")
    #define MAXN 1010
    #define MAX(a,b) a>b?a:b
    #define blank pf("
    ")
    #define LL long long
    #define ALL(x) x.begin(),x.end()
    #define INS(x) inserter(x,x.begin())
    #define pqueue priority_queue
    #define INF 0x3f3f3f3f
    
    struct node
    {
        int h,c,a;
    }p[405];
    
    int K;
    
    bool dp[40005];
    
    int used[40005];
    
    int cmp(const node& x,const node& y)
    {
        return x.a<y.a;
    }
    
    int main()
    {
        int i,j,k;
        while(~sf("%d",&K))
        {
            for(i=1;i<=K;i++)
            {
                sf("%d%d%d",&p[i].h,&p[i].a,&p[i].c);
            }
    
            sort(p+1,p+K+1,cmp);
    
            /*
            for(i=1;i<=K;i++)
            {
                pf("%d %d %d
    ",p[i].h,p[i].a,p[i].c);
            }*/
    
            mem(dp,false);
            dp[0] = true;
            int ans = 0;
            for(i=1;i<=K;i++)
            {
                mem(used,0);
                for(j=p[i].h;j<=p[i].a;j++)
                {
                    if(!dp[j] && dp[j-p[i].h] && used[j-p[i].h]<p[i].c)
                    {
                        dp[j] = true;
                        used[j] = used[j-p[i].h] + 1;
                        //pf("%d %d %d
    ",i,j,used[j]);
                        if(ans<j) ans = j;
                    }
                }
            }
            pf("%d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    postman简单传参,上个接口的返回值作为下个接口的入参。
    python 给定URL 如何获取其内容,并将其保存至HTML文档。
    外键关联on_delete参数含义
    excel导入与导出
    序列化关系
    使用框架的各种代码示例
    国产celery简单使用
    selecte_related 函数优化查询
    django 之 配置文件
    类与缓存问题 类与属性的关系
  • 原文地址:https://www.cnblogs.com/qlky/p/5640582.html
Copyright © 2011-2022 走看看