博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ2392
阅读量:4309 次
发布时间:2019-06-06

本文共 1262 字,大约阅读时间需要 4 分钟。

题意:奶牛们要用K个不同类型的石头建太空电梯.每一种石头的高度为Hi,数量为Ci,且不能放在高于Ai的地方,求最高能建多高的太空电梯.

分析:多重背包,数组标记.显然将ai小的放在下面会更优.所以先排序.

code:

const maxh=41000;var   cnt:array[0..maxh] of longint;      h,a,c:array[0..401] of longint;      f:array[0..maxh] of boolean;      n,i,j,k,tmp,ans:longint;      procedure swap(var a,b:longint);      var   tmp:longint;      begin            tmp:=a; a:=b; b:=tmp;      end;      procedure sort(l,r:longint);      var   i,j,mid:longint;      begin            i:=l; j:=r;            mid:=a[(l+r)>>1];            while i<=j do            begin                  while a[i]
mid do dec(j); if i<=j then begin swap(h[i],h[j]); swap(a[i],a[j]); swap(c[i],c[j]); inc(i); dec(j); end; end; if i
l then sort(l,j); end;begin readln(n); for i:=1 to n do readln(h[i],a[i],c[i]); sort(1,n); f[0]:=true; for i:=1 to n do begin fillchar(cnt,sizeof(cnt),0); for j:=0 to a[i] do if (f[j]=true)and(not f[j+h[i]])and(j+h[i]<=a[i])and(cnt[j]

转载于:https://www.cnblogs.com/exponent/archive/2011/08/12/2136501.html

你可能感兴趣的文章
TZC Intercommunication System
查看>>
HDU 4571 SPFA+DP
查看>>
centos 创建以日期为名的文件夹
查看>>
Java Timer触发定时器
查看>>
Page Object设计模式
查看>>
程序的基础知识
查看>>
FreeModbus在STM32上移植(转)
查看>>
使用 pjax 载入的新页面,新页面上 类方法 无法被触发?
查看>>
sql server从一个数据库复制一个表到另一个数据库的方法
查看>>
微软正式公布Win8版本 ARM版命名为Windows RT
查看>>
4.java设计模式-原型模式(prototype)
查看>>
Javaee -----01----javaee的环境搭建和html标签 ...
查看>>
JVM内存分布和垃圾回收
查看>>
DOM操作指令
查看>>
PHPCMS快速建站系列之类别调用及类别显示页面
查看>>
《第二章 感知机》
查看>>
HomeWork1_Login in
查看>>
javascript中的类
查看>>
新词发现博文收集
查看>>
input text focus去掉默认光影
查看>>