您有 5、10、20、50、100 的硬币,
其重量分别为 2g、3g、10g、25g、50g。你的钱包很弱,所以你不能超过 391 克的重量。你只能在里面放 3 个相同价值的硬币。你能说一下你钱包的最大价值是多少吗?
询问 :::change([(Five,Ten,Twenty,Fifty,Hundred),W,S])
range(I,I,[I]).
range(I,K,[I|L]) :-
I < K,
I1 is I + 1,
range(I1,K,L).
coin(X,L) :-
range(0,3,L1),
member(X,L1).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
change([(Five,Ten,Twenty,Fifty,Hundred),W,S]) :-
coin(Five,L),
coin(Ten,L),
coin(Twenty,L),
coin(Fifty,L),
coin(Hundred,L),
W1 = 50*Hundred + 25*Fifty + 10*Twenty +3*Ten+ 2*Five,
S1 = 5*Five+ 10*Ten+ 20*Twenty + 50*Fifty + 100*Hundred,
W1 < 391,
W is W1,
S is S1,
maximum(S1).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
maximum(S1) :-
S is S1,
threshold(S),
not( S1 < S).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
threshold(S1) :-
M is S1,
not( M < 451).