A - Space Elevator

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <= 400) different types of blocks with which to build the tower. Each block of type i has height h_i (1 <= h_i <= 100) and is available in quantity c_i (1 <= c_i <= 10). Due to possible damage caused by cosmic rays, no part of a block of type i can exceed a maximum altitude a_i (1 <= a_i <= 40000).

Help the cows build the tallest space elevator possible by stacking blocks on top of each other according to the rules.

Input

* Line 1: A single integer, K

* Lines 2..K+1: Each line contains three space-separated integers: h_i, a_i, and c_i. Line i+1 describes block type i.

Output

* Line 1: A single integer H, the maximum height of a tower that can be built

Sample Input

  1. 3
  2. 7 40 3
  3. 5 23 8
  4. 2 52 6

Sample Output

  1. 48
  2.  
  3. 题意:有一群牛要上太空,他们计划建一个太空梯(用一些石头垒),他们有k种不同类型的石头,每一种石头的高度为h,数量为c,由于会受到太空辐射,每一种石头不能超过这种石头的最大建造高度a,求解利用这些石头所能修建的太空梯的最高的高度.
     多重背包问题,与一般的多重背包问题所不同的知识多了一个限制条件就是某些"物品"叠加起来的"高度"不能超过一个值,于是我们可以对他们的最高可能达到高度进行排序,然后就是一般的多重背包问题了
  4.  
  5. 思路:
    首先是录入数据,这一点比较简单,但是最好用scanf,因为它比cin快;
    录入之后对各个数据按照最大的使用高度进行排序,就会转化成一个一般的多重背包为题,一开始我是用原始的多重背包做的麻烦并且也没有A了,最后看了一下题解,是因为每种块的使用个数的计算处理不当;
  1. #include <iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<algorithm>
  6. #include<memory.h>
  7. using namespace std;
  8. int a[];
  9. struct node
  10. {
  11. int h;
  12. int max;
  13. int shu;
  14. };
  15. node num[];
  16. int dp[];
  17. bool cmp(node a,node b)
  18. {
  19. return a.max<b.max;
  20. }
  21. int main()
  22. {
  23. // freopen("1.txt","r",stdin);
  24. int i,j,k;
  25. int m;
  26. memset(dp,,sizeof(dp));
  27. dp[]=;
  28. int sum[];
  29. cin>>k;
  30. for(i=;i<k;i++)
  31. {
  32. scanf("%d%d%d",&num[i].h,&num[i].max,&num[i].shu);
  33. }
  34. sort(num,num+k,cmp);
  35. m=num[k-].max;
  36. int ans=;
  37. for(i=;i<k;i++)
  38. {
  39. memset(sum,,sizeof(sum));
  40. for(j=num[i].h;j<=num[i].max;j++)
  41. {
  42. if(!dp[j]&&dp[j-num[i].h]&&sum[j-num[i].h]<num[i].shu)
  43. {
  44. dp[j]=;
  45. sum[j]=sum[j-num[i].h]+;//提柜条件,表示到达j高度已经用的砖的个数
  46. if(ans<j)
  47. ans=j;
  48. }
  49. }
  50. }
  51. cout<<ans<<endl;
  52. return ;
  53. }
  1.  

A - Space Elevator(动态规划专项)的更多相关文章

  1. poj[2392]space elevator

    Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...

  2. poj 2392 Space Elevator(多重背包+先排序)

    Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...

  3. BZOJ 1739: [Usaco2005 mar]Space Elevator 太空电梯

    题目 1739: [Usaco2005 mar]Space Elevator 太空电梯 Time Limit: 5 Sec  Memory Limit: 64 MB Description The c ...

  4. POJ 2392 Space Elevator(多重背包变形)

    Q: 额外添加了最大高度限制, 需要根据 alt 对数据进行预处理么? A: 是的, 需要根据 alt 对数组排序 Description The cows are going to space! T ...

  5. poj2392 Space Elevator(多重背包问题)

    Space Elevator   Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8569   Accepted: 4052 ...

  6. POJ 2392 Space Elevator(贪心+多重背包)

    POJ 2392 Space Elevator(贪心+多重背包) http://poj.org/problem?id=2392 题意: 题意:给定n种积木.每种积木都有一个高度h[i],一个数量num ...

  7. POJ2392:Space Elevator

    Space Elevator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9244   Accepted: 4388 De ...

  8. POJ 2392 Space Elevator DP

    该题与POJ 1742的思路基本一致:http://www.cnblogs.com/sevenun/p/5442279.html(多重背包) 题意:给你n个电梯,第i个电梯高h[i],数量有c[i]个 ...

  9. DP:Space Elevator(POJ 2392)

    太空电梯 题目大意:一群牛想造电梯到太空,电梯都是由一个一个块组成的,每一种块不能超过这个类型的高度,且每一种块都有各自的高度,有固定数量,问最高能造多高. 这题就是1742的翻版,对ai排个序就可以 ...

随机推荐

  1. 用Python做SVD文档聚类---奇异值分解----文档相似性----LSI(潜在语义分析)

    转载请注明出处:电子科技大学EClab——落叶花开http://www.cnblogs.com/nlp-yekai/p/3848528.html SVD,即奇异值分解,在自然语言处理中,用来做潜在语义 ...

  2. .net 在数据访问层中写一个DBhelper优化类

    复习了在学校的时候做的WinForm端的一个学生信息管理系统,用的三层架构,看了一下里面的数据优化类 这个类是用来把对数据库的操作封装成静态方法,增删改查的时候直接调用这个类,减少项目里代码的冗余和方 ...

  3. 深入了解css3新特性

    深入了解css3新特性:http://www.ibm.com/developerworks/cn/web/1202_zhouxiang_css3/

  4. 变形属性 transform

    transform功能可以实现文字或图像的旋转.绽放.倾斜.与移动: 注意点:1.其移动.旋转.倾斜.与绽放这4种效果的使用先后顺序不同,页面会显示不同的结果: 2.属性值有一个参数与有多个参数的别: ...

  5. 3、href和src的区别

    href:将现在的页面连接到新的页面 src:将需要引用的东西添加到现在的页面 <a href="mailto:youremailaddress@host.com">C ...

  6. 在.Net MVC中自定义ValidationAttribute标签对Model中的属性做验证

    写一个继承与ValidationAttribute类的自定义的验证方法 MVC中传递数据时,大多数都会用Model承载数据,并且在传到控制器后,对Model进行一系列的验证. 我平时经常使用的判断方法 ...

  7. 【翻译】编译Cordova项目

    针对iOS创建项目 需要安装iOS SDK才能创建Workshop项目 打开终端工具并使用cd命令进入workshop目录执行下面都命令 cordova build ios 项目建立在workshop ...

  8. Linux kernel Vhost-net 和 Virtio-net代码详解

    场景 Host上运行qemu kvm虚拟机,其中虚拟机的网卡类型为virtio-net,而Host上virtio-net backend使用vhost-net 数据包进入虚拟机代码分析 首先看vhos ...

  9. jquery正则常用的

    jQuery.validator.addMethod("mobilePhone",function(value,element){ return this.optional(ele ...

  10. ajax请求相关方法

    jquery的ajax请求相关方法有多个: 1.$.ajax() 示例: <!DOCTYPE html> <html> <head> <meta charse ...