zoukankan      html  css  js  c++  java
  • hdu 3033 I love sneakers! 分组背包

    I love sneakers!

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

    Problem 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
     
    Source
    题意:n个东西,最多k组,有T块钱,每组最少选一个
    思路:分组背包;
       首先初始化为-inf; 
       选了一个以后就可以进行01背包了;
    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define pi (4*atan(1.0))
    #define eps 1e-14
    const int N=1e4+100,M=4e6+10,inf=1e9+10,mod=1e9+7;
    const ll INF=1e18+10;
    int dp[11][N];
    int v[11][N],w[11][N];
    int si[11];
    int main()
    {
        int n,T,k;
        while(~scanf("%d%d%d",&n,&T,&k))
        {
            memset(si,0,sizeof(si));
            memset(dp[0],0,sizeof(dp[0]));
            for(int i=1;i<=n;i++)
            {
                int flag;
                scanf("%d",&flag);
                scanf("%d%d",&v[flag][si[flag]],&w[flag][si[flag]]);
                si[flag]++;
            }
            for(int i=1;i<=k;i++)
            {
                for(int t=0;t<=T;t++)
                dp[i][t]=-inf;
                for(int t=0;t<si[i];t++)
                {
                    for(int j=T;j>=v[i][t];j--)
                    {
                        dp[i][j]=max(dp[i][j],dp[i][j-v[i][t]]+w[i][t]);
                        dp[i][j]=max(dp[i][j],dp[i-1][j-v[i][t]]+w[i][t]);
                    }
                }
            }
            if(dp[k][T]>=0)
                printf("%d
    ",dp[k][T]);
            else
                printf("Impossible
    ");
        }
        return 0;
    }
  • 相关阅读:
    java.lang.NoClassDefFoundError: Lorg/slf4j/Logger;
    jetty9内嵌到应用,并在启动后加载WebApplicationInitializer,可运行jsp
    Gradle Maven 依赖管理
    gradle多模块开发
    Github .gitignore详解
    Could not find or load main class org.gradle.wrapper.GradleWrapperMain解决办法
    SOC 与 ARM
    Codis集群的搭建与使用
    TIDB VS COCKROACHEB
    mysql故障
  • 原文地址:https://www.cnblogs.com/jhz033/p/5950804.html
Copyright © 2011-2022 走看看