青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

poj1276

Cash Machine

Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 18125 Accepted: 6307

Description

A Bank plans to install a machine for cash withdrawal. The machine is able to deliver appropriate @ bills for a requested cash amount. The machine uses exactly N distinct bill denominations, say Dk, k=1,N, and for each denomination Dk the machine has a supply of nk bills. For example,

N=3, n1=10, D1=100, n2=4, D2=50, n3=5, D3=10

means the machine has a supply of 10 bills of @100 each, 4 bills of @50 each, and 5 bills of @10 each.

Call cash the requested amount of cash the machine should deliver and write a program that computes the maximum amount of cash less than or equal to cash that can be effectively delivered according to the available bill supply of the machine.

Notes:
@ is the symbol of the currency delivered by the machine. For instance, @ may stand for dollar, euro, pound etc.

Input

The program input is from standard input. Each data set in the input stands for a particular transaction and has the format:

cash N n1 D1 n2 D2 ... nN DN

where 0 <= cash <= 100000 is the amount of cash requested, 0 <=N <= 10 is the number of bill denominations and 0 <= nk <= 1000 is the number of available bills for the Dk denomination, 1 <= Dk <= 1000, k=1,N. White spaces can occur freely between the numbers in the input. The input data are correct.

Output

For each set of data the program prints the result to the standard output on a separate line as shown in the examples below.

Sample Input

735 3  4 125  6 5  3 350
633 4  500 30  6 100  1 5  0 1
735 0
0 3  10 100  10 50  10 10

Sample Output

735
630
0
0

Hint

The first data set designates a transaction where the amount of cash requested is @735. The machine contains 3 bill denominations: 4 bills of @125, 6 bills of @5, and 3 bills of @350. The machine can deliver the exact amount of requested cash.

In the second case the bill supply of the machine does not fit the exact amount of cash requested. The maximum cash that can be delivered is @630. Notice that there can be several possibilities to combine the bills in the machine for matching the delivered cash.

In the third case the machine is empty and no cash is delivered. In the fourth case the amount of cash requested is @0 and, therefore, the machine delivers no cash.



這個題描述不好,搞得我很亂,就是有一個cash大小的背包,有n中物品,每種物品有nk個,每個費用dk,問包里最多能裝多少,

這是個多重背包,但是物品數特別多,有10*1000個最多,

剛開始沒注意,tle了,然后想到要用背包九講中講的二進制拆分的思想

把每種物品分成1*w[i],2*w[i],4*w[i],……,2^k *w[i],(num[i]-2^(k+1)+1) *w[i] 這樣物品數就大大降低了,物品數變成了log(num)

因為每個數都可以用多個2的幾次方組成,

還有肯能的優化是有的物品費用超過了背包體積,直接舍去就可以了

 1#include<stdio.h>
 2#include<string.h>
 3#include<math.h>
 4#define MAX 10000
 5int v,n,w[MAX],num[20];
 6int f[100100],ww;
 7int i,j,k;
 8int tot,t;
 9int max(int a,int b)
10{
11    if (a>b) return a;
12    else return b;
13}

14int main()
15{
16    while (scanf("%d%d",&v,&n)!=EOF)
17    {
18        tot=0;
19        for (i=1; i<=n ; i++ )
20        {
21            scanf("%d%d",&num[i],&ww);
22            if (num[i]!=0)
23            {
24                tot++;
25                w[tot]=ww;
26                num[i]--;
27            }

28            t=2;
29            while (num[i]>=t)
30            {
31                num[i]-=t;
32                tot++;
33                w[tot]=t*ww;
34                t=t*2;
35            }

36            if (num[i]>0)
37            {
38                tot++;
39                w[tot]=num[i]*ww;
40            }

41        }

42        memset(f,0,sizeof(f));
43        for (i=1; i<=tot ; i++ )
44            for (j=v; j>=w[i]; j-- )
45            {
46                f[j]=max(f[j],f[j-w[i]]+w[i]);
47            }

48        {
49        }

50        printf("%d\n",f[v]);
51    }

52    return 0;
53}

54


posted on 2012-02-20 15:40 jh818012 閱讀(306) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


<2025年11月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

導航

統計

常用鏈接

留言簿

文章檔案(85)

搜索

最新評論

  • 1.?re: poj1426
  • 我嚓,,輝哥,,居然搜到你的題解了
  • --season
  • 2.?re: poj3083
  • @王私江
    (8+i)&3 相當于是 取余3的意思 因為 3 的 二進制是 000011 和(8+i)
  • --游客
  • 3.?re: poj3414[未登錄]
  • @王私江
    0ms
  • --jh818012
  • 4.?re: poj3414
  • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
  • --王私江
  • 5.?re: poj1426
  • 評論內容較長,點擊標題查看
  • --王私江
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            一区二区三区色| 亚洲人成毛片在线播放女女| 国产在线播精品第三| 9色精品在线| 每日更新成人在线视频| 亚洲免费在线电影| 国产精品第一页第二页第三页| 亚洲高清影视| 蜜臀久久99精品久久久画质超高清| 亚洲中字黄色| 国产精品一卡二| 亚洲欧洲av一区二区三区久久| 亚洲乱码国产乱码精品精98午夜| 欧美成人福利视频| 日韩视频在线一区二区| 亚洲精品国产日韩| 久久网站热最新地址| 久久精品免费| 欧美精品成人91久久久久久久| 一区在线播放视频| 欧美色图五月天| 一区二区三区**美女毛片| 亚洲第一黄色网| 欧美a级理论片| 亚洲精品影视在线观看| 亚洲缚视频在线观看| 免费看的黄色欧美网站| 亚洲精品久久久久久下一站| 亚洲激情小视频| 欧美日韩另类一区| 午夜精品一区二区三区电影天堂| 亚洲图片欧美日产| 国产真实乱子伦精品视频| 免费观看成人www动漫视频| 美女图片一区二区| 在线视频欧美日韩精品| 亚洲永久精品大片| 加勒比av一区二区| 亚洲人体大胆视频| 国产精品午夜久久| 免费久久精品视频| 欧美日韩中字| 久久综合久久久| 欧美日韩国产一区精品一区| 欧美一区激情视频在线观看| 蜜臀av一级做a爰片久久| 亚洲欧美日本日韩| 久久久久国色av免费观看性色| 亚洲人成网站在线播| 亚洲视频欧洲视频| 亚洲成人在线视频网站| 日韩视频免费看| 伊人激情综合| 亚洲视频中文字幕| 最新国产乱人伦偷精品免费网站 | 悠悠资源网亚洲青| 亚洲美女在线一区| 国产一区二区三区电影在线观看 | 久久婷婷激情| 午夜在线a亚洲v天堂网2018| 欧美成人精品1314www| 久久国产一区二区| 欧美三级黄美女| 欧美大片在线观看| 国产小视频国产精品| 99精品欧美| 亚洲国产高清视频| 久久岛国电影| 久久av免费一区| 国产精品成人一区二区三区夜夜夜 | 在线日韩中文字幕| 亚洲一区二区3| 99国产麻豆精品| 久久一区二区三区四区| 久久精品男女| 国产精品日韩一区二区| 99成人免费视频| 亚洲裸体视频| 欧美黄色一区| 亚洲国产精品电影在线观看| 狠狠入ady亚洲精品| 午夜国产欧美理论在线播放| 亚洲在线视频一区| 国产精品精品视频| 亚洲桃色在线一区| 小黄鸭精品密入口导航| 国产精品久久综合| 亚洲影院免费观看| 久久精品视频一| 国内精品久久久| 久久成人资源| 欧美高清日韩| 日韩午夜激情av| 欧美日韩卡一卡二| 99在线观看免费视频精品观看| 日韩亚洲欧美在线观看| 欧美精选午夜久久久乱码6080| 亚洲日本欧美| 亚洲午夜免费福利视频| 欧美亚韩一区| 香蕉尹人综合在线观看| 久久精品国产一区二区三区| 一区在线视频| 欧美成人一区二区三区在线观看| 亚洲人成网在线播放| 在线天堂一区av电影| 国产精品另类一区| 午夜激情综合网| 欧美91视频| 亚洲视频福利| 国产婷婷精品| 欧美91精品| 制服丝袜亚洲播放| 久久视频一区| 亚洲精品国产精品乱码不99按摩| 欧美日韩成人在线观看| 亚洲综合色丁香婷婷六月图片| 久久久免费观看视频| 亚洲欧洲日本国产| 国产精品久久久久久影视| 亚洲欧美日韩一区在线观看| 蜜臀91精品一区二区三区| 日韩午夜精品视频| 国产一区二区剧情av在线| 狼人社综合社区| 亚洲午夜未删减在线观看| 久久美女性网| 在线视频你懂得一区二区三区| 国产视频一区二区三区在线观看| 免费一级欧美在线大片| 亚洲一区二区三区乱码aⅴ蜜桃女| 久热精品在线| 亚洲一区二区三区激情| 欲香欲色天天天综合和网| 欧美性理论片在线观看片免费| 久久不射2019中文字幕| 亚洲美女av在线播放| 久久夜色精品亚洲噜噜国产mv| 一本色道久久综合亚洲精品不卡 | 久久婷婷久久| 亚洲一级网站| 国产亚洲欧美日韩日本| 狼狼综合久久久久综合网| 亚洲免费av片| 欧美sm重口味系列视频在线观看| 亚洲一区二三| 亚洲日本成人女熟在线观看| 国产麻豆日韩欧美久久| 欧美精品久久天天躁| 久久狠狠亚洲综合| 亚洲午夜视频在线| 亚洲激情网址| 欧美v日韩v国产v| 久久精品女人的天堂av| 亚洲欧美另类在线观看| 一本色道久久综合亚洲精品婷婷| 伊人男人综合视频网| 国产乱理伦片在线观看夜一区| 欧美日韩八区| 欧美激情一区二区三区成人| 开元免费观看欧美电视剧网站| 欧美一区二区三区免费看 | 最新国产乱人伦偷精品免费网站| 久久亚洲午夜电影| 久久久国际精品| 久久精品国产亚洲5555| 欧美一区免费视频| 欧美一级欧美一级在线播放| 亚洲综合导航| 亚洲欧美日韩在线综合| 亚洲一级黄色片| 亚洲男人第一av网站| 亚洲自拍都市欧美小说| 亚洲影院免费| 中文亚洲欧美| 亚洲欧美激情视频在线观看一区二区三区| 日韩亚洲欧美精品| 中文精品视频| 亚洲欧美在线高清| 欧美一区三区三区高中清蜜桃| 欧美在线视频观看| 久久精品国产v日韩v亚洲| 久久久精彩视频| 另类av导航| 欧美国产视频日韩| 亚洲国产精品成人综合| 亚洲精品少妇网址| 在线视频欧美精品| 亚洲欧美成aⅴ人在线观看| 欧美一区二区免费视频| 久久全球大尺度高清视频| 免费一级欧美在线大片| 欧美日韩国产丝袜另类| 国产精品毛片| 影音先锋日韩有码| 日韩午夜黄色| 午夜宅男久久久| 免费91麻豆精品国产自产在线观看| 欧美国产欧美综合| 亚洲看片免费|