Usaco Shopping offers (multiple complete backpack)

Source: Internet
Author: User

There is a person to go out to buy things, the supermarket introduced a number of preferential information, each offer can be used more than once, each offer information limits the need to use this offer information to purchase the type of items and the number of each item.

Ask for the minimum cost that the person will need to buy all the items they want.

After the analysis, the coupon is used as the item, the amount of the goods to be bought is the capacity, and the cost is the value.

/*id:modengd1prog:shoppinglang:c++*/#include <iostream> #include <stdio.h> #include <memory.h># Include <vector>int indexofcode[1000];//number I of the commodity after the discretization of the subscript int buyofindex[5];//number I of the product total buy how many int priceofindex[5];// The original price of the item with the discretized coordinates i is struct offer{int kind,price;//the kind of goods contained in this offer information, this offer information represents the price int code[5];//each commodity code int num[5];//each commodity Limited number of};offer Offers[100];bool isuseful[100];//The offer information that is labeled I is available, if the message contains items that I do not need, the using namespace Std;int s;//    Number of offers information int b;//The number of goods to buy int dp[6][6][6][6][6];void getinput ()//input {memset (buyofindex,0,sizeof (Buyofindex));    scanf ("%d", &s);        for (int i=0;i<s;i++) {scanf ("%d", &offers[i].kind);        for (int j=0;j<offers[i].kind;j++) {scanf ("%d%d", &offers[i].code[j],&offers[i].num[j]);    } scanf ("%d", &offers[i].price);    } scanf ("%d", &b);    int c,k,p;        for (int i=0;i<b;i++) {scanf ("%d%d%d", &c,&k,&p);        indexofcode[c]=i;//to the item numberBuyofindex[i]=k;    Priceofindex[i]=p; }//To determine which coupons cannot be used memset (isuseful,0x01,sizeof (isuseful));//Initialize All to True for (int i=0;i<s;i++) {for (int j=0 j<offers[i].kind;j++) {//the item in the offer information is not required by the customer, or the quantity limit of an item in the offer information is greater than the quantity that the customer wants to buy if (indexofcode[offer s[i].code[j]]>=b| | Buyofindex[indexofcode[offers[i].code[j]]]<offers[i].num[j]) {cout<<indexofcode[offers [i].code[j]]<< ' <<B<<buyofindex[Offers[i].code[j]]<< ' <<Offers[i].num[j]<<                Endl                Isuseful[i]=false;            Break            }}}}void Slove () {//Initialize all items at the original price when purchased for (Int. a=0;a<=5;a++) for (int b=0;b<=5;b++)                        for (int c=0;c<=5;c++) for (int. d=0;d<=5;d++) for (int e=0;e<=5;e++)    DP[A][B][C][D][E]=A*PRICEOFINDEX[0]+B*PRICEOFINDEX[1]+C*PRICEOFINDEX[2]+D*PRICEOFINDEX[3]+E*PRICEOFINDEX[4]; for (int i=0;i&lT        s;i++) {if (!isuseful[i]) continue;        int items[5];        memset (items,0,sizeof (items));        for (int j=0;j<offers[i].kind;j++) {items[indexofcode[offers[i].code[j]]]=offers[i].num[j]; } for (int a=items[0];a<=5;a++) for (int b=items[1];b<=5;b++) for (int c=items[2];c&lt                            ; =5;c++) for (int. d=items[3];d <=5;d++) for (int e=items[4];e<=5;e++) Dp[a][b][c][d][e]=min (Dp[a][b][c][d][e],dp[a-items[0]][b-items[1]][c-items[2]][d-items[3]][e-items[4])    +offers[i].price); } Cout<<dp[buyofindex[0]][buyofindex[1]][buyofindex[2]][buyofindex[3]][buyofindex[4]]<<endl;}    int main () {freopen ("shopping.in", "R", stdin);    Freopen ("Shopping.out", "w", stdout);    GetInput ();    Slove (); return 0;}

  

Usaco Shopping offers (multiple complete backpack)

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.