zoukankan      html  css  js  c++  java
  • HDOJ_ACM_悼念512汶川大地震遇难同胞——珍惜现在,感恩生活

    Problem Description
    急!灾区的食物依然短缺!
    为了挽救灾区同胞的生命,心系灾区同胞的你准备自己采购一些粮食支援灾区,现在假设你一共有资金n元,而市场有m种大米,每种大米都是袋装产品,其价格不等,并且只能整袋购买。
    请问:你用有限的资金最多能采购多少公斤粮食呢?

    后记:
    人生是一个充满了变数的生命过程,天灾、人祸、病痛是我们生命历程中不可预知的威胁。
    月有阴晴圆缺,人有旦夕祸福,未来对于我们而言是一个未知数。那么,我们要做的就应该是珍惜现在,感恩生活——
    感谢父母,他们给予我们生命,抚养我们成人;
    感谢老师,他们授给我们知识,教我们做人
    感谢朋友,他们让我们感受到世界的温暖;
    感谢对手,他们令我们不断进取、努力。 
    同样,我们也要感谢痛苦与艰辛带给我们的财富~

     
    Input
    输入数据首先包含一个正整数C,表示有C组测试用例,每组测试用例的第一行是两个整数n和m(1<=n<=100, 1<=m<=100),分别表示经费的金额和大米的种类,然后是m行数据,每行包含3个数p,h和c(1<=p<=20,1<=h<=200,1<=c<=20),分别表示每袋的价格、每袋的重量以及对应种类大米的袋数。
     
    Output
    对于每组测试数据,请输出能够购买大米的最多重量,你可以假设经费买不光所有的大米,并且经费你可以不用完。每个实例的输出占一行。
     
    Sample Input
    1
    8 2
    2 100 4
    4 100 2
     
    Sample Output
    400
     
    Code
    View Code
    View Code
    Key Points
    The first one is just using 0/1 knapsack, you can get the answer.
    For the second one , I classified the situations and dissicuss. the things which you will be confuse maybe the efficial 0/1 knapsack. 
     
    Efficial 0/1 knapsack for the same things:
    for example, 7, it can be made up by 001 010 and 111. 
    To begin with, make the 001 010 things into the bag, then rest packet is 3.
    Secondly, take the 3 things into the bag one by one.
    If you still fell confuse, you can draw it out. Maybe you will understand.
     
     
     
     
  • 相关阅读:
    1020 Tree Traversals
    1021 Deepest Root
    1022 Digital Library
    1023 Have Fun with Numbers
    1024 Palindromic Number
    1025 PAT Ranking
    1026 Table Tennis
    面向对象知识点梳理篇一
    面向对象知识点梳理篇二
    logging模块
  • 原文地址:https://www.cnblogs.com/chuanlong/p/2797127.html
Copyright © 2011-2022 走看看