zoukankan      html  css  js  c++  java
  • UVa 10130 SuperSale

    SuperSale

    There is a SuperSale in a SuperHiperMarket. Every person can take only one object of each kind, i.e. one TV, one carrot, but for extra low price. We are going with a whole family to that SuperHiperMarket. Every person can take as many objects, as he/she can carry out from the SuperSale. We have given list of objects with prices and their weight. We also know, what is the maximum weight that every person can stand. What is the maximal value of objects we can buy at SuperSale?

    Input Specification

    The input consists of T test cases. The number of them (1<=T<=1000) is given on the first line of the input file.

    Each test case begins with a line containing a single integer number that indicates the number of objects (1 <= N <= 1000). Then follows Nlines, each containing two integers: P and W. The first integer (1<=P<=100) corresponds to the price of object. The second  integer (1<=W<=30) corresponds to the weight of object. Next line contains one integer (1<=G<=100)  it’s the number of people in our group. Next G lines contains maximal weight (1<=MW<=30) that can stand this i-th person from our family (1<=i<=G).

    Output Specification

    For every test case your program has to determine one integer. Print out the maximal value of goods which we can buy with that family.

    Sample Input

    2

    3

    72 17

    44 23

    31 24

    1

    26

    6

    64 26

    85 22

    52 4

    99 18

    39 13

    54 9

    4

    23

    20

    20

    26

    Output for the Sample Input

    72

    514

    01背包问题,唯一有点变形的就是这道题中是一群人组团去的,只要对每个人做01背包的动态规划,最后再求和即可

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 
     5 using namespace std;
     6 
     7 int n,g,mw;
     8 int p[1050],w[1050];
     9 int dp[35];
    10 
    11 int main()
    12 {
    13     int kase;
    14 
    15     scanf("%d",&kase);
    16 
    17     while(kase--)
    18     {
    19         scanf("%d",&n);
    20         for(int i=0;i<n;i++)
    21             scanf("%d %d",&p[i],&w[i]);
    22         scanf("%d",&g);
    23 
    24         int total=0;
    25         for(int k=0;k<g;k++)
    26         {
    27             scanf("%d",&mw);
    28             memset(dp,0,sizeof(dp));
    29             for(int i=0;i<n;i++)
    30                 for(int j=mw;j>=w[i];j--)
    31                     if(dp[j-w[i]]+p[i]>dp[j])
    32                         dp[j]=dp[j-w[i]]+p[i];
    33             int Max=-1;
    34             for(int i=0;i<=mw;i++)
    35                 if(dp[i]>Max)
    36                     Max=dp[i];
    37             total+=Max;
    38         }
    39 
    40         printf("%d
    ",total);
    41     }
    42 
    43     return 0;
    44 }
    [C++]
  • 相关阅读:
    rest-framework之路由
    rest-framework之频率控制
    mysql 模糊查询 concat()
    解决spring使用动态代理
    MySQL巧用sum,case...when...优化统计查询
    解决maven项目中有小红叉的问题
    google ---gson字符串数组用GSON解析然后用逗号隔开拼接,去掉最后一个逗号
    Elicpse使用技巧-打开选中文件文件夹或者包的当前目录
    powdesigner建表
    遍历map
  • 原文地址:https://www.cnblogs.com/lzj-0218/p/3567698.html
Copyright © 2011-2022 走看看