zoukankan      html  css  js  c++  java
  • HDU-3033 I love sneakers!

    http://acm.hdu.edu.cn/showproblem.php?pid=3033

    分组背包。

    我参考的解题报告:

    http://blog.sina.com.cn/s/blog_6ec19c780100w1nn.html

    I love sneakers!

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3500    Accepted Submission(s): 1428

    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
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    int dp[20][10010];
    using namespace std;
    int Max(int x,int y)
    {
        if(x>y)
         return x;
         else
         return y;
    }
    struct trade
    {
        int w,v;
    }ve[20][10010];
    int main()
    {
        int N,M,K,num[20],i,j,k,a,b,c;
        while(scanf("%d%d%d", &N, &M, &K) != EOF)
        {
            memset(num,0,sizeof(num));
            for(i=0;i<N;i++)
            {
              cin>>a>>b>>c;
              ve[a][num[a]].w=b;
              ve[a][num[a]].v=c;
               num[a]++;
            }
            memset(dp,-1,sizeof(dp));//表示不合法。
            for(i=0;i<=M;i++)
               dp[0][i]=0;//i=1;能计算。
             for(i=1;i<=K;i++)//i表示几种牌子的鞋子。
               for(j=0;j<num[i];j++)//表示1种牌子的有几样。
                 for(k=M;k>=ve[i][j].w;k--)//每一样的价值。
    
                  {
                      if(dp[i][k-ve[i][j].w]!=-1)
                            dp[i][k]=Max(dp[i][k],dp[i][k-ve[i][j].w]+ve[i][j].v);
                      if(dp[i-1][k-ve[i][j].w]!=-1)
                            dp[i][k]=Max(dp[i][k],dp[i-1][k-ve[i][j].w]+ve[i][j].v);
                  }
                  if(dp[K][M]<0)
                  {
    
                      printf("Impossible
    ");
                  }
    
                  else
                     cout<<dp[K][M]<<endl;
        }
        return 0;
    }
    
     
  • 相关阅读:
    未分类[selenium]常见元素定位
    未分类[selenium]-元素定位不到的原因及解决办法
    1.4测试需求分析
    1.3测试用例设计方法
    1.2软件生命周期&测试流程
    《Python 高级编程》简要读书笔记
    app基本测试要点总结
    python 找出两个列表的相同元素与不同元素
    mysql 8.0之后关于group by 语句报错问题
    selenium webdriver 执行原理
  • 原文地址:https://www.cnblogs.com/cancangood/p/3599373.html
Copyright © 2011-2022 走看看