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

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.



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

這是個(gè)多重背包,但是物品數(shù)特別多,有10*1000個(gè)最多,

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

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

因?yàn)槊總€(gè)數(shù)都可以用多個(gè)2的幾次方組成,

還有肯能的優(yōu)化是有的物品費(fèi)用超過了背包體積,直接舍去就可以了

 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)  編輯 收藏 引用


只有注冊用戶登錄后才能發(fā)表評論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


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

導(dǎo)航

統(tǒng)計(jì)

常用鏈接

留言簿

文章檔案(85)

搜索

最新評論

  • 1.?re: poj1426
  • 我嚓,,輝哥,,居然搜到你的題解了
  • --season
  • 2.?re: poj3083
  • @王私江
    (8+i)&3 相當(dāng)于是 取余3的意思 因?yàn)?3 的 二進(jìn)制是 000011 和(8+i)
  • --游客
  • 3.?re: poj3414[未登錄]
  • @王私江
    0ms
  • --jh818012
  • 4.?re: poj3414
  • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
  • --王私江
  • 5.?re: poj1426
  • 評論內(nèi)容較長,點(diǎn)擊標(biāo)題查看
  • --王私江
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美午夜久久久| 欧美黄色aaaa| 老司机一区二区| 欧美一级欧美一级在线播放| 一区二区三区四区蜜桃| 影音先锋另类| 韩国一区二区三区在线观看| 国产精品国产a级| 国产精品看片资源| 国产欧美日韩一区二区三区在线| 国产精品一区在线观看| 狠狠色狠狠色综合日日91app| 黄色综合网站| 99av国产精品欲麻豆| 欧美一区二区三区免费在线看| 久久成人精品无人区| 久久综合网色—综合色88| 亚洲激情不卡| 亚洲破处大片| 亚洲欧美日韩精品在线| 欧美日韩综合视频| 欧美+日本+国产+在线a∨观看| 亚洲电影av在线| 亚洲欧美国产精品专区久久| 性欧美长视频| 欧美高清在线播放| 国产亚洲欧美一区| 亚洲黄色在线| 性欧美在线看片a免费观看| 久久免费视频这里只有精品| 亚洲美女福利视频网站| 亚洲午夜视频在线观看| 新狼窝色av性久久久久久| 另类欧美日韩国产在线| 欧美日产在线观看| 影音先锋亚洲一区| 久久成人免费电影| 亚洲毛片在线免费观看| 欧美综合激情网| 国产精品99久久不卡二区| 篠田优中文在线播放第一区| 欧美日本中文字幕| 亚洲人成毛片在线播放| 亚洲视频1区| 欧美sm视频| 欧美亚洲日本国产| 欧美日韩精品久久久| 亚洲电影av| 美女999久久久精品视频| 亚洲在线免费观看| 欧美日韩一级大片网址| 亚洲精品日产精品乱码不卡| 久久中文在线| 欧美一区影院| 国产亚洲人成a一在线v站| 亚洲精品视频在线观看免费| 亚洲精品日韩一| 亚洲人成亚洲人成在线观看| 久久精品亚洲一区二区| 国产一区二区福利| 久久久成人精品| 性色av一区二区三区在线观看 | 亚洲一区二区三区在线观看视频| 美脚丝袜一区二区三区在线观看| 香蕉久久一区二区不卡无毒影院| 国产精品理论片| 亚洲一区美女视频在线观看免费| 国产精品高精视频免费| 亚洲综合三区| 亚洲男人的天堂在线| 欧美日韩国产综合在线| 黄色成人在线观看| 欧美电影免费观看大全| 国产精品你懂得| 午夜在线观看免费一区| 一区二区三区精密机械公司| 国产精品久久久久久久久动漫 | 国产综合网站| 免费观看一级特黄欧美大片| 欧美亚洲一级| 久久久亚洲精品一区二区三区| 中国亚洲黄色| 国产拍揄自揄精品视频麻豆| 午夜精品在线看| 亚洲欧洲在线免费| 久久婷婷国产麻豆91天堂| 精品动漫3d一区二区三区免费版 | 国产综合色一区二区三区| 免费中文字幕日韩欧美| 欧美日韩久久| 欧美一区二区三区四区在线| 久久国内精品视频| 一本一本久久a久久精品综合妖精 一本一本久久a久久精品综合麻豆 | 亚洲少妇中出一区| 久久精品道一区二区三区| 亚洲电影免费在线观看| 亚洲激情在线激情| 国产麻豆精品视频| 免费人成精品欧美精品| 欧美日韩黄色大片| 免费不卡视频| 在线一区二区三区四区| 欧美国产亚洲另类动漫| 国产伦精品一区二区三| 依依成人综合视频| 亚洲第一在线综合网站| 国产精品免费观看视频| 午夜精品一区二区三区在线播放| 久久久亚洲影院你懂的| 亚洲天堂免费观看| 欧美一区二区视频网站| 亚洲国产第一| 久久免费少妇高潮久久精品99| 韩国av一区二区三区| 蜜臀va亚洲va欧美va天堂| 久久一本综合频道| 亚洲免费在线观看视频| 麻豆成人精品| 久久夜色精品国产欧美乱| 欧美体内she精视频在线观看| 久久免费视频网| 国产精品免费久久久久久| 男同欧美伦乱| 国内精品久久国产| 午夜精品国产精品大乳美女| 亚洲国产日韩欧美综合久久| 亚洲欧美中文日韩v在线观看| 一本色道久久综合亚洲精品按摩| 欧美亚洲一区二区三区| 欧美一区二区视频免费观看| 欧美激情精品久久久六区热门| 亚洲欧美在线看| 国产精品私房写真福利视频| 亚洲美女91| 亚洲精品国产精品国自产在线| 亚洲欧美日韩精品久久亚洲区| 免费观看成人| 欧美日韩国产精品专区| 午夜精品久久久久久99热| 美脚丝袜一区二区三区在线观看 | 9国产精品视频| 欧美成人精品一区二区| 亚洲字幕在线观看| 国产精品久久波多野结衣| 日韩视频在线观看一区二区| 在线国产亚洲欧美| 亚洲欧美日韩高清| 久久久精品国产一区二区三区| 国产欧美在线| 欧美亚洲免费在线| 亚洲一本视频| 欧美激情四色 | 美女精品在线| 亚洲第一主播视频| 欧美破处大片在线视频| 亚洲精品少妇| 亚洲中字黄色| 黄色国产精品| 久久精品av麻豆的观看方式| 欧美激情一区二区三区蜜桃视频 | 亚洲精品免费电影| 亚洲精品一区二区三区在线观看| 免费亚洲一区| 91久久午夜| 日韩一级大片| 欧美天天视频| 亚洲欧美激情一区| 久久精品国产一区二区三| 好吊色欧美一区二区三区四区| 久久国产手机看片| 亚洲国产三级网| 99精品99| 国产自产精品| 欧美精品在欧美一区二区少妇| 99在线精品免费视频九九视| 亚洲视屏一区| 国产欧美日韩精品丝袜高跟鞋| 久久久水蜜桃av免费网站| 亚洲伦理在线| 欧美尤物巨大精品爽| 一区二区三区在线观看国产| 欧美成人精品激情在线观看 | 久久久久成人精品| 亚洲精品国精品久久99热| 一区二区三区成人| 国产精品久久久久久久浪潮网站| 久久久久久一区二区| 亚洲精品1区| 久久综合九色九九| 亚洲一区激情| 红桃视频国产精品| 国产精品亚洲综合色区韩国| 久久视频一区| 欧美午夜片在线免费观看| 亚洲精品久久久久久下一站| 久久夜色精品国产亚洲aⅴ| 亚洲影音一区| 亚洲欧洲一区二区三区| 国产区亚洲区欧美区| 欧美α欧美αv大片|