Codevs "1025" Selected dishes

Source: Internet
Author: User

1025 Selected Dishestime limit: 1 sspace limit: 128000 KBtitle level: Golden GoldTitle Description Description

In the small pine hostel downstairs not far, there is the most good PK University canteen--the Farmer's canteen (nm canteen). Because the canteen dishes are very good, the price is fair, so many people like to come here to eat. The Farmer ' s canteen a la carte way as in a supermarket, people go in from a designated intersection and then come out and pay for a designated intersection. Since the number of diners here is more, people consciously enter the mouth when they lined up a long line, along the long-standing table with a variety of dishes for the selection of dishes.

Komatsu found that this way of choosing means that he could not leave the team at the time of the meal to pick up some of the dishes he had already seen or had not seen, because queue jumping is impolite, but also by BS.

Each dish has a value, and Komatsu also set a delicious value for each dish in his view, such as braised small yellow croaker in the small Komatsu is very delicious value, and cauliflower in Komatsu is very low-value food. Some dishes are extremely nutritious (such as rice), so no matter how much it tastes, Komatsu will choose 1 servings. Now Komatsu brought X yuan to the canteen to eat, he would like to know, in the case of not owed , his choice of dishes of the total value of the greatest sum is how much.

Enter a description Input Description

Please read the relevant data from the input file farmer.in. The first line of input includes two integers n(1≤n),K(0k actual dish type) and a real number X(0≤x100), indicating that there are n dishes, k vegetables are required, Komatsu brought X yuan (accurate to the "angle"). The next 1 lines contain n real numbers, representing the price of all dishes on the menu table from the entrance to the exit (0 the price 10, the unit "Yuan", and the exact "angle"); The next 1 lines contain n An integer representing the delicious value of all dishes from the entrance to the exit of the dish table (0 the delicious value 100); The next line contains n integers, indicating the type number of all dishes on the menu table from entrance to exit (1 type number 100). The last line contains k integers , each representing the type number of the required dish. Note that the same number of dishes can appear multiple times, but their price and delicious value are the same. For the same vegetable (whether it is a required dish), Komatsu will only choose 1 servings (buy two servings of braised tofu is more boring ah). Also, the price of the required dish must not exceed X.

Output description Output Description

Please output the results to the output file farmer.out. The output contains an integer that indicates the maximum sum of the delicious value of the dish that Komatsu can choose.

Note: You can assume that the data does not appear in the small loose band money is not enough to buy a must buy food situation.

Sample input Sample Input

7 1 5.0

4 1 3 0.9 2 0.5 0.9

7 3 5 2 5 0 2

6 3 5 2 4 1 2

2

Sample output Sample Output

10

This problem is a limited backpack DP, so we just need to add a limit.

Use a vis array to indicate whether the dish has been selected, read the data, the selected dish's vis value is assigned to 1, then the backpack DP can, but pay attention to the price of the dish and all the money x10 into an integer, otherwise the backpack DP will appear dead loop ...

Code:

1#include <cstdio>2#include <iostream>3#include <cstdlib>4#include <cmath>5#include <vector>6#include <algorithm>7#include <cstring>8#include <vector>9#include <map>Ten#include <stack> One #defineMAXN 100+50 A #defineINF 0x7fffffff - #defineXiao 1e-9 - using namespacestd; the intn,k,w[maxn],kind[maxn],dp[Ten*MAXN]; - intMONEY,PRICE[MAXN],VIS[MAXN],PRICE_[MAXN],W_[MAXN]; - intMain () - { +     intans=0; -     intnum; +     DoubleMoney1; Ascanf"%D%D%LF",&n,&k,&money1); atMoney=money1*Ten; -      for(intI=1; i<=n;++i) scanf ("%LF", &money1), price[i]=money1*Ten; -      for(intI=1; i<=n;++i) scanf ("%d",&w[i]); -      for(intI=1; i<=n;++i) -     { -scanf"%d",&kind[i]); invis[kind[i]]=1; -price_[kind[i]]=Price[i]; tow_[kind[i]]=W[i]; +     } -      for(intI=1; i<=n;++i) vis[i]=1; the      for(intI=1; i<=k;++i) *     { $scanf"%d",&num);Panax Notoginsengvis[num]=0; -money-=Price_[num]; theans+=W_[num]; +  } A      for(intI=1; i<=n;++i) the       { +           if(Vis[i]) -               for(intj=money;j>=price_[i];j--) $              { $Dp[j]=max (dp[j],dp[j-price_[i]]+w_[i]); -              } -       } thecout<<dp[money]+ans; -       return 0;Wuyi } the            -                     Wu  -     
Code Code Oi oi

Codevs "1025" Selected dishes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.