• 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;
    }
    
     
  • 相关阅读:
    [深度概念]·K-Fold 交叉验证 (Cross-Validation)的理解与应用
    [天池竞赛项目]2019菜鸟全球科技挑战赛 —智能体积测量(队员招募)
    [MXNet逐梦之旅]练习一·使用MXNet拟合直线手动实现
    [深度学习工具]·极简安装Dlib人脸识别库
    [数据科学从零到壹]·泰坦尼克号生存预测(数据读取、处理与建模)​​​​​​​
    Java 多线程
    javaAPI中的常用 类 以及接口
    QQ数据库管理
    java 对象和封装
    事务、视图、索引、备份、还原
  • 原文地址:https://www.cnblogs.com/cancangood/p/3599373.html
Copyright © 2020-2023  润新知