• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 12,  comments - 16,  trackbacks - 0
              
            Shopping Offers
            IOI'95

            In a certain shop, each kind of product has an integer price. For example, the price of a flower is 2 zorkmids (z) and the price of a vase is 5z. In order to attract more customers, the shop introduces some special offers.

            A special offer consists of one or more product items together for a reduced price, also an integer. Examples:

            • three flowers for 5z instead of 6z, or
            • two vases together with one flower for 10z instead of 12z.

            Write a program that calculates the price a customer has to pay for a purchase, making optimal use of the special offers to make the price as low as possible. You are not allowed to add items, even if that would lower the price.

            For the prices and offers given above, the (lowest) price for three flowers and two vases is 14z: two vases and one flower for the reduced price of 10z and two flowers for the regular price of 4z.

            PROGRAM NAME: shopping

            INPUT FORMAT

            The input file has a set of offers followed by a purchase.
            Line 1: s, the number of special offers, (0 <= s <= 99).
            Line 2..s+1: Each line describes an offer using several integers. The first integer is n (1 <= n <= 5), the number of products that are offered. The subsequent n pairs of integers c and k indicate that k items (1 <= k <= 5) with product code c (1 <= c <= 999) are part of the offer. The last number p on the line stands for the reduced price (1 <= p <= 9999). The reduced price of an offer is less than the sum of the regular prices.
            Line s+2: The first line contains the number b (0 <= b <= 5) of different kinds of products to be purchased.
            Line s+3..s+b+2: Each of the subsequent b lines contains three values: c, k, and p. The value c is the (unique) product code (1 <= c <= 999). The value k indicates how many items of this product are to be purchased (1 <= k <= 5). The value p is the regular price per item (1 <= p <= 999). At most 5*5=25 items can be in the basket.

            SAMPLE INPUT (file shopping.in)

            2
            1 7 3 5
            2 7 1 8 2 10
            2
            7 3 2
            8 2 5
            

            OUTPUT FORMAT

            A single line with one integer: the lowest possible price to be paid for the purchases.

            SAMPLE OUTPUT (file shopping.out)

            14

            解答:
            0 <= b <= 5,1 <= k <= 5,可用5*5*5*5*5的DP 每種買0~5個,可以用6進制表示,然后5維DP~OK!

            狀態設置:F[a1][a2][a3][a4][a5]為買a1件物品1,a2件物品2,a3件物品3,a4件物品4,a5件物品5時,所需的最少價格

            邊界條件:F[0][0][0][0][0]=0;

            狀態轉移方程:
            F[a1][a2][a3][a4][a5]=min{F[ a1-P[i][1] ][ a2-P[i][2] ][ a3-P[i][3] ][ a4-P[i][4] ][ a5-P[i][5] ]+P[i][0]}
            其中i=1..s+b; 且 ak-p[i][k]>=0

            /*
            ID: kuramaw1
            PROG: shopping
            LANG: C++
            */

            #include 
            <fstream>
            #include 
            <cstring>


            using std::ifstream;
            using std::ofstream;
            using std::endl;

            #define  MAX_T(a,b) ((a)>(b)?(a):(b))

            #define  MAX 5
            #define  MAX_S 100

            int f[MAX+1][MAX+1][MAX+1][MAX+1][MAX+1];//min price

            short s,b;
            short s_p[MAX_S],component[MAX_S][MAX],p_num[MAX],p[MAX],p_t(0),order[MAX];

            inline 
            short product_code_to_order(short code)
            {
                
            for(int i=0;i<p_t;i++)
                 
            if(p_num[i]==code)
                     
            return i;
                p_num[p_t
            ++]=code;
                
            return (p_t-1);

            }

            int main()
            {
                ifstream 
            in("shopping.in");
                
            in>>s;
                memset(component,
            0,sizeof(component));
                
            for(int i=0;i<s;i++)
                {
                    
            short n;
                    
            in>>n;
                    
            for(int j=0;j<n;j++)
                    {
                        
            short c,k;
                        
            in>>c>>k;
                        component[i][product_code_to_order(c)]
            =k;
                    }
                    
            in>>s_p[i];
                        
                }

                memset(order,
            0,sizeof(order));
                memset(p,
            0,sizeof(p));
                
            in>>b;
                
            for(int i=0;i<b;i++)
                {
                    
            short c,k,p1;
                    
            in>>c>>k>>p1;
                    
            short n=product_code_to_order(c);
                    order[n]
            =k;
                    p[n]
            =p1;
                }
                
            in.close();

                
            //do dp
                short ii[MAX];
            #define loop(i)  for(ii[i]=0;ii[i]<=order[i];ii[i]++)
            #define  F(a) f[a[0]][a[1]][a[2]][a[3]][a[4]]
                
                loop(
            0) loop(1) loop(2) loop(3) loop(4)
                {

                    F(ii)
            =ii[0]*p[0]+ii[1]*p[1]+ii[2]*p[2]+ii[3]*p[3]+ii[4]*p[4];
                    
            for(short j=0;j<s;j++)
                    {
                        
            short t[MAX];
                        
            for(short k=0;k<5;k++)
                            t[k]
            =MAX_T(0,ii[k]-component[j][k]);
                        
            if(F(t)+s_p[j]<F(ii))
                            F(ii)
            =F(t)+s_p[j];

                    }
                }

                
            //out
                ofstream out("shopping.out");
                
            out<<F(order)<<endl;
                
            out.close();


            }


            posted on 2009-08-13 11:46 kuramawzw 閱讀(479) 評論(0)  編輯 收藏 引用 所屬分類: USACO
            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            常用鏈接

            留言簿(5)

            隨筆分類

            隨筆檔案

            文章檔案

            Algorithm

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            伊人色综合久久天天网| 狠狠色丁香婷婷综合久久来来去 | 久久综合久久自在自线精品自| 欧洲性大片xxxxx久久久| 亚洲精品tv久久久久久久久| 国产精品久久久久…| 久久精品无码一区二区三区免费| 亚洲伊人久久综合中文成人网| 久久久久久无码Av成人影院| 久久黄视频| 久久亚洲国产成人精品性色| 久久久久97国产精华液好用吗| 国产激情久久久久久熟女老人 | 热99re久久国超精品首页| 久久99热这里只有精品国产| 亚洲人成无码久久电影网站| 国产精品久久久久久福利漫画| 久久国产精品99久久久久久老狼| 亚洲欧美成人久久综合中文网| 精品国产一区二区三区久久久狼 | 无码日韩人妻精品久久蜜桃| 久久精品国产亚洲Aⅴ蜜臀色欲| 亚洲国产精品久久久天堂| 亚洲国产精品无码久久久久久曰| 国产精品久久久久AV福利动漫| 伊人久久综合无码成人网| 久久亚洲AV永久无码精品| 成人精品一区二区久久| 国产成人精品久久免费动漫 | 久久香蕉国产线看观看乱码| 日日噜噜夜夜狠狠久久丁香五月| 久久久午夜精品| 久久亚洲中文字幕精品一区| 亚洲伊人久久综合影院| 日本亚洲色大成网站WWW久久| 国产精品欧美亚洲韩国日本久久| 国产亚洲美女精品久久久久狼| 久久ww精品w免费人成| 久久国产乱子伦免费精品| 久久国产高潮流白浆免费观看| 久久综合狠狠综合久久|