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

    I love sneakers!

    Time Limit: 1000ms
    Memory Limit: 32768KB
    This problem will be judged on HDU. Original ID: 3033
    64-bit integer IO format: %I64d      Java class name: Main
    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

     
    解题:不知道是什么背包。。。感觉像分组1n背包。。。
     
     1 #include <bits/stdc++.h>
     2 #define pii pair<int,int>
     3 using namespace std;
     4 const int maxn = 110;
     5 int n,m,o,dp[11][10001];
     6 vector< pii >goods[maxn];
     7 int main(){
     8     int a,b,c;
     9     while(~scanf("%d %d %d",&n,&m,&o)){
    10         for(int i = 0; i < maxn; ++i) goods[i].clear();
    11         for(int i = 0; i < n; ++i){
    12             scanf("%d %d %d",&a,&b,&c);
    13             goods[a].push_back(make_pair(b,c));
    14         }
    15         memset(dp,-1,sizeof dp);
    16         memset(dp[0],0,sizeof dp[0]);
    17         for(int i = 1; i <= o; ++i){
    18             for(int j = 0; j < goods[i].size(); ++j){
    19                 for(int k = m; k >= goods[i][j].first; --k){
    20                     if(dp[i][k - goods[i][j].first] >= 0)
    21                         dp[i][k] = max(dp[i][k],dp[i][k-goods[i][j].first] + goods[i][j].second);
    22                     if(dp[i-1][k - goods[i][j].first] >= 0)
    23                         dp[i][k] = max(dp[i][k],dp[i-1][k-goods[i][j].first] + goods[i][j].second);
    24                 }
    25             }
    26         }
    27         if(dp[o][m] >= 0) printf("%d
    ",dp[o][m]);
    28         else puts("Impossible");
    29     }
    30     return 0;
    31 }
    View Code
  • 相关阅读:
    (转)typedef用法
    (转)在用户空间发生中断时,上下文切换的过程
    (转)内核中断,异常,抢占总结篇
    (转)中断上下文和进程上下文的区别
    (转)C中的volatile用法
    (转)gcc学习笔记
    (转)C系程序员面试必知必会之大端小端
    (转)我在北京工作这几年 – 一个软件工程师的反省
    (转)忠告
    Linux下VLAN功能的实现 (转)
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4448332.html
Copyright © 2011-2022 走看看