搞定
结果是36.11。物品取舍是01010001010101010100
程序代码:
#include<stdio.h> int v[] = { 20, 23, 25, 28, 31, 42, 53, 61, 62, 70, 74, 83, 97, 98, 102, 112, 118, 125, 128, 130}; double p[] = { 1.10, 1.46, 1.47, 1.83, 1.84, 1.67, 2.08, 3.70, 3.70, 4.25, 4.28, 5.06, 5.61, 5.80, 6.10, 6.60, 6.84, 7.41, 7.42, 7.45}; int main() { int ms, tv, i, j; double mp, tp; mp = 0; for(i = 1; i < (1 << 20); i++) { tv = tp = 0; for(j = 0; j < 20; j++) if((i >> j) & 1) { tv += v[j]; tp += p[j]; } if(tv > 600) continue; if(tp > mp) { ms = i; mp = tp; } } for(i = 0; i < 20; printf("%d", (ms >> i++) & 1)); printf("\nthe max price is %.2f\n", mp); return 0; }
结果是36.11。物品取舍是01010001010101010100
重剑无锋,大巧不工