hdu 4091 整数规划

hdu 4091 整数规划

Problem Description

Some brave warriors come to a lost village. They are very lucky and find a lot of treasures and a big treasure chest, but with angry zombies.
The warriors are so brave that they decide to defeat the zombies and then bring all the treasures back. A brutal long-drawn-out battle lasts from morning to night and the warriors find the zombies are undead and invincible.
Of course, the treasures should not be left here. Unfortunately, the warriors cannot carry all the treasures by the treasure chest due to the limitation of the capacity of the chest. Indeed, there are only two types of treasures: emerald and sapphire. All of the emeralds are equal in size and value, and with infinite quantities. So are sapphires.
Being the priest of the warriors with the magic artifact: computer, and given the size of the chest, the value and size of each types of gem, you should compute the maximum value of treasures our warriors could bring back.

Input

There are multiple test cases. The number of test cases T (T <= 200) is given in the first line of the input file. For each test case, there is only one line containing five integers N, S1, V1, S2, V2, denoting the size of the treasure chest is N and the size and value of an emerald is S1 and V1, size and value of a sapphire is S2, V2. All integers are positive and fit in 32-bit signed integers.

Output

For each test case, output a single line containing the case number and the maximum total value of all items that the warriors can carry with the chest.

Sample Input

2
100 1 1 2 2
100 34 34 5 3

Sample Output

Case #1: 100
Case #2: 86

题目分析

max ⁡ Z = V 1 x 1 + V 2 x 2 { S 1 x 1 + S 2 x 2 ≤ N x 1 ≥ 0 , x 2 ≥ 0 x 1 和 x 2 都 是 整 数 \max Z=V_1x_1+V_2x_2\\ \left\{\begin{matrix} S_1x_1+S_2x_2\leq N\\ x_1\geq0,x_2\geq0\\ x_1和x_2都是整数 \end{matrix}\right. maxZ=V1x1+V2x2S1x1+S2x2Nx10,x20x1x2
max ⁡ Z = x 1 + 2 x 2 { x 1 + 2 x 2 ≤ 100 x 1 ≥ 0 , x 2 ≥ 0 x 1 和 x 2 都 是 整 数 \max Z=x_1+2x_2\\ \left\{\begin{matrix} x_1+2x_2\leq 100\\ x_1\geq0,x_2\geq0\\ x_1和x_2都是整数 \end{matrix}\right. maxZ=x1+2x2x1+2x2100x10,x20x1x2
松弛问题:
max ⁡ Z = x 1 + 2 x 2 { x 1 + 2 x 2 ≤ 100 x 1 ≥ 0 , x 2 ≥ 0 \max Z=x_1+2x_2\\ \left\{\begin{matrix} x_1+2x_2\leq 100\\ x_1\geq0,x_2\geq0\\ \end{matrix}\right. maxZ=x1+2x2{x1+2x2100x10,x20

x B x_B xB x 1 x_1 x1 x 2 x_2 x2 x 3 x_3 x3 b b b
x 3 x_3 x3121100
λ j \lambda_j λj120

x 3 x_3 x3出基, x 2 x_2 x2进基,

x B x_B xB x 1 x_1 x1 x 2 x_2 x2 x 3 x_3 x3 b b b
x 3 x_3 x30.510.550
λ j \lambda_j λj-10-1

则最优解为 ( x 1 , x 2 ) = ( 0 , 50 ) (x_1,x_2)=(0,50) (x1,x2)=(0,50),最优值为 2 × 50 = 100 2\times 50=100 2×50=100
max ⁡ Z = 34 x 1 + 3 x 2 { 34 x 1 + 5 x 2 ≤ 100 x 1 ≥ 0 , x 2 ≥ 0 x 1 和 x 2 都 是 整 数 \max Z=34x_1+3x_2\\ \left\{\begin{matrix} 34x_1+5x_2\leq 100\\ x_1\geq0,x_2\geq0\\ x_1和x_2都是整数 \end{matrix}\right. maxZ=34x1+3x234x1+5x2100x10,x20x1x2松弛问题:
max ⁡ Z = 34 x 1 + 3 x 2 { 34 x 1 + 5 x 2 ≤ 100 x 1 ≥ 0 , x 2 ≥ 0 \max Z=34x_1+3x_2\\ \left\{\begin{matrix} 34x_1+5x_2\leq 100\\ x_1\geq0,x_2\geq0\\ \end{matrix}\right. maxZ=34x1+3x2{34x1+5x2100x10,x20

x B x_B xB x 1 x_1 x1 x 2 x_2 x2 x 3 x_3 x3 b b b
x 3 x_3 x33451100
λ j \lambda_j λj3430

x 3 x_3 x3出基, x 1 x_1 x1进基,

x B x_B xB x 1 x_1 x1 x 2 x_2 x2 x 3 x_3 x3 b b b
x 3 x_3 x31 5 34 \frac{5}{34} 345 1 34 \frac{1}{34} 341 100 34 \frac{100}{34} 34100
λ j \lambda_j λj0-2-1

则最优解为 ( x 1 , x 2 ) = ( 100 34 , 0 ) (x_1,x_2)=(\frac{100}{34},0) (x1,x2)=(34100,0),不是整数解。
分支定界法:加入约束 x 1 ≤ 2 x_1\leq 2 x12,因为 34 × 3 > 100 34\times3>100 34×3>100不满足第一条约束,所以约束 x 1 ≥ 3 x_1\geq3 x13不考虑
max ⁡ Z = 34 x 1 + 3 x 2 { 34 x 1 + 5 x 2 ≤ 100 x 1 ≤ 2 x 1 ≥ 0 , x 2 ≥ 0 \max Z=34x_1+3x_2\\ \left\{\begin{matrix} 34x_1+5x_2\leq 100\\ x_1\leq2\\ x_1\geq0,x_2\geq0\\ \end{matrix}\right. maxZ=34x1+3x234x1+5x2100x12x10,x20

x B x_B xB x 1 x_1 x1 x 2 x_2 x2 x 3 x_3 x3 x 4 x_4 x4 b b b
x 3 x_3 x334510100
x 4 x_4 x410012
λ j \lambda_j λj34300

x 4 x_4 x4出基, x 1 x_1 x1进基

x B x_B xB x 1 x_1 x1 x 2 x_2 x2 x 3 x_3 x3 x 4 x_4 x4 b b b
x 3 x_3 x3051-3432
x 1 x_1 x110012
λ j \lambda_j λj030-34

x 3 x_3 x3出基, x 2 x_2 x2进基

x B x_B xB x 1 x_1 x1 x 2 x_2 x2 x 3 x_3 x3 x 4 x_4 x4 b b b
x 2 x_2 x201 1 5 \frac{1}{5} 51 − 34 5 \frac{-34}{5} 534 32 5 \frac{32}{5} 532
x 1 x_1 x110012
λ j \lambda_j λj00 − 3 5 \frac{-3}{5} 53 − 68 34 \frac{-68}{34} 3468

则最优解为 ( x 1 , x 2 ) = ( 2 , 32 5 ) (x_1,x_2)=(2,\frac{32}{5}) (x1,x2)=(2,532),不是整数解。
分支定界法:加入约束 x 2 ≤ 6 x_2\leq 6 x26,因为 34 × 2 + 5 × 7 > 100 34\times2+5\times7>100 34×2+5×7>100不满足第一条约束,所以约束 x 2 ≥ 7 x_2\geq7 x27不考虑
max ⁡ Z = 34 x 1 + 3 x 2 { 34 x 1 + 5 x 2 ≤ 100 x 1 ≤ 2 x 2 ≤ 6 x 1 ≥ 0 , x 2 ≥ 0 \max Z=34x_1+3x_2\\ \left\{\begin{matrix} 34x_1+5x_2\leq 100\\ x_1\leq2\\ x_2\leq 6\\ x_1\geq0,x_2\geq0\\ \end{matrix}\right. maxZ=34x1+3x234x1+5x2100x12x26x10,x20

x B x_B xB x 1 x_1 x1 x 2 x_2 x2 x 3 x_3 x3 x 4 x_4 x4 x 5 x_5 x5 b b b
x 3 x_3 x3345100100
x 4 x_4 x4100102
x 5 x_5 x5010016
λ j \lambda_j λj343000

x 4 x_4 x4出基, x 1 x_1 x1进基

x B x_B xB x 1 x_1 x1 x 2 x_2 x2 x 3 x_3 x3 x 4 x_4 x4 x 5 x_5 x5 b b b
x 3 x_3 x3051-34032
x 1 x_1 x1100102
x 5 x_5 x5010116
λ j \lambda_j λj030-340

x 5 x_5 x5出基, x 2 x_2 x2进基

x B x_B xB x 1 x_1 x1 x 2 x_2 x2 x 3 x_3 x3 x 4 x_4 x4 x 5 x_5 x5 b b b
x 3 x_3 x3001-3902
x 1 x_1 x1100102
x 2 x_2 x2010116
λ j \lambda_j λj000-37-3

最优解为 ( x 1 , x 2 ) = ( 2 , 6 ) (x_1,x_2)=(2,6) (x1,x2)=(2,6),最优值为 34 × 2 + 3 × 6 = 68 + 18 = 86 34\times 2+3\times 6=68+18=86 34×2+3×6=68+18=86

单纯形法模板
上面是实现思路,代码有空来补。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值