Hdu3591the trouble of Xiaoqian multiple backpack + Full backpack

Source: Internet
Author: User

//Give the value of Xiaoqian coins and the number of each kind of money//Merchant's number of each kind of money is infinite, Xiaoqian pay 20000//Ask how to pay the minimum number of coins in the transaction//xiaoqian is a multi-pack .//Merchant is full backpack#include <cstdio>#include <cstring>#include <iostream>using namespace STD;Const intMAXN =20010;Const intINF =0x3f3f3f3f;intDP[MAXN];intDP_1[MAXN];intC[MAXN],V[MAXN];intN, T;intCAS =0;intMain () {//freopen ("In.txt", "R", stdin);     while(scanf("%d%d", &n, &t) && (n+t)) { for(inti =1; I <= n;i++)scanf("%d", &v[i]); for(inti =1; I <= n;i++)scanf("%d", &c[i]); for(inti =1; i < maxn;i++) dp[i] = dp_1[i] = inf; dp_1[0] =0; dp[0] =0; for(inti =1; I <= n;i++) for(intj = V[i]; J < Maxn; J + +) Dp_1[j] = min (Dp_1[j], Dp_1[j-v[i]] +1) ; for(inti =1; I <= n;i++) { for(intK =1; k <= c[i];k*=2)            { for(intj = MAXN-1; J >= k*v[i];j--) dp[j] = min (Dp[j], Dp[j-k*v[i]] + k);            C[i]-=k; } for(intj = maxn-1; J >= c[i]*v[i];j--) dp[j] = min (Dp[j], Dp[j-c[i]*v[i]] + c[i]); }intans = inf; for(inti = t; I <= MAXN-Ten; i++)if(Dp[i]! = INF && dp_1[i-t]! = inf) ans = min (dp[i] + dp[i-t], ans);printf("Case%d:", ++cas);if(ans = = inf)puts("-1") ;Else cout<<ans<<endl; }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hdu3591the trouble of Xiaoqian multiple backpack + Full 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.