• 分组背包


    F - I love sneakers!
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
    Submit Status

    Description

    After months of hard working, Iserlohn finally wins awesome amount of scholarship. As a great zealot of sneakers, he decides to spend all his money on them in a sneaker store.

    There are several brands of sneakers that Iserlohn wants to collect, such as Air Jordan and Nike Pro. And each brand has released various products. For the reason that Iserlohn is definitely a sneaker-mania, he desires to buy at least one product for each brand.
    Although the fixed price of each product has been labeled, Iserlohn sets values for each of them based on his own tendency. With handsome but limited money, he wants to maximize the total value of the shoes he is going to buy. Obviously, as a collector, he won’t buy the same product twice.
    Now, Iserlohn needs you to help him find the best solution of his problem, which means to maximize the total value of the products he can buy.
     

    Input

    Input contains multiple test cases. Each test case begins with three integers 1<=N<=100 representing the total number of products, 1 <= M<= 10000 the money Iserlohn gets, and 1<=K<=10 representing the sneaker brands. The following N lines each represents a product with three positive integers 1<=a<=k, b and c, 0<=b,c<100000, meaning the brand’s number it belongs, the labeled price, and the value of this product. Process to End Of File.
     

    Output

    For each test case, print an integer which is the maximum total value of the sneakers that Iserlohn purchases. Print "Impossible" if Iserlohn's demands can’t be satisfied.
     

    Sample Input

    5 10000 3 1 4 6 2 5 7 3 4 99 1 55 77 2 44 66
     

    Sample Output

    255
     1 Home    Problems    Status    Contest    [xiong_tao]    Logout
     2 xiong_tao 's source code for F
     3 Memory: 4908 KB         Time: 265 MS
     4 Language: G++         Result: Accepted
     5 
     6 1
     7 2
     8 3
     9 4
    10 5
    11 6
    12 7
    13 8
    14 9
    15 10
    16 11
    17 12
    18 13
    19 14
    20 15
    21 16
    22 17
    23 18
    24 19
    25 20
    26 21
    27 22
    28 23
    29 24
    30 25
    31 26
    32 27
    33 28
    34 29
    35 
    36 #include<cstdio>
    37 #include<string.h>
    38 using namespace std;
    39 int p[120],m[120],v[120],dp[120][10010];
    40 int max1(int x,int y,int z)
    41 {
    42     x=x>y?x:y;
    43     x=x>z?x:z;
    44     return x;
    45 }
    46 int main()
    47 {
    48     int n,d,k;
    49     int i,j,a;
    50     while(scanf("%d%d%d",&n,&d,&k)!=EOF)
    51     {
    52         for(i=0; i<n; i++)
    53             scanf("%d%d%d",&p[i],&m[i],&v[i]);
    54         memset(dp,0,sizeof(dp));
    55         for(i=1; i<=k; i++)
    56             for(j=0; j<n; j++)
    57                 for(a=d; a>=0; a--)
    58                     if(a>=m[j]&&p[j]==i)
    59                         dp[i][a]=max1(dp[i-1][a-m[j]]+v[j],dp[i][a],dp[i][a-m[j]]+v[j]);
    60         if(dp[k][d]) printf("%d
    ",dp[k][d]);
    61         else printf("Impossible
    ");
    62     }
    63     return 0;
    64 }
    65 
    66 FAQ | About Virtual Judge | Forum | Discuss | Open Source Project
    67 All Copyright Reserved ©2010-2012 HUST ACM/ICPC TEAM
    68 Anything about the OJ, please ask in the forum, or contact author:Isun
    69 Server Time: 2014-07-28 20:21:39
  • 相关阅读:
    linux学习(六)计划任务命令
    如何在在手机上安装linux(ubuntu )关键词:Termux
    linux学习(五)用户与组管理命令,以及用户信息文件解释
    linux学习(四)复制(cp)移动(mv)删除(rm)查找(find)文件、文件夹操作、软硬链接的区别
    Flutter中通过https post Json接收Json
    Api管家系列(一):初探
    Api管家系列(三):测试和Rest Client
    Api管家系列(二):编辑和继承Class
    JDK8 时间相关API基本使用
    windows杀端口
  • 原文地址:https://www.cnblogs.com/angledamon/p/3873927.html
Copyright © 2020-2023  润新知