sample input
735 3 4 125 6 5 3 350sample output633 4 500 30 6 100 1 5 0 1
735 0
0 3 10 100 10 50 10 10
7356300
0題意:你的銀行卡裡有 cash 元,而atm機裡有 n 種面值的錢,n行每種錢的數量和面值。
問 最多能從這台atm機裡取出多少錢。
裸的完全揹包
可是我居然寫錯了。。。。
在當前物品的數量*價值 大於等於 揹包容量時,就可以將當前物品的數量視作無限,for迴圈的時候就從小到大正序遍歷。
小於等於的時候 就將物品數量轉換成二進位制下的01揹包 這裡是01揹包!!!
#include#includeview code#include
using
namespace
std;
intcash, n;
int c[15],w[15
];int dp[100005
];void completepack(int c,int
w)else
for(int j=cash;j>=w*c;j--)
dp[j] = max(dp[j],dp[j-w*c]+w*c);
}}int
main()
for(int i=0;i)
printf(
"%d\n
",dp[cash]);
}return0;
}
POJ1276 多重揹包(01揹包 完全揹包)
多重揹包模板題,給定揹包容量 v 給定 n 種物品,每種物品的個數 n i 體積 v i 和重量 w i 已知,求揹包能裝下的物品的最大重量。對應本題就是,給定提款的金額cash,給定 n 種錢幣,每種錢幣的個數為 n i 面額 d i 已知,求能兌換的錢幣的最大值。本題中,體積和重量都等於面額。7...
poj1276 多重揹包
題意 取款機的問題 有 n 種錢 每種錢有 v i 的價值 每種錢有 w i 張 問給定要取得錢 cash 之後能從取款機最多取多少錢 理解 多重揹包 直接套模板 遞推式 dp i max dp i dp i mul v i mul v i 其中的值根據 定義 如下 include include ...
POJ 1276 混合揹包
發現不能按照揹包九講上直接將各種揹包封裝成函式的方式來寫,會re 對於揹包結果存在上限的,直接在轉移時加上限制即可 include include include using namespace std int dp 100001 int cnt 11 number int d 11 denomin...