LoginSignup
0
0

More than 3 years have passed since last update.

ASP 例題1 コイン問題(制約充足問題)

Last updated at Posted at 2020-02-16

問題

1円硬貨,5円硬貨,10円硬貨を合計で15枚,それぞれを1枚以上持っている. 金額の合計は90円である. それぞれの硬貨を何枚持っているか?

回答

example1.lp
{coin_1yen(1..15)}=1.
{coin_5yen(1..15)}=1.
{coin_10yen(1..15)}=1.

:- not 15 = X + Y + Z, coin_1yen(X), coin_5yen(Y), coin_10yen(Z). 
:- not 90 = X + 5*Y + 10*Z, coin_1yen(X), coin_5yen(Y), coin_10yen(Z).

解説

{coin_1yen(1..15)}=1.は、「coin_1yenは1~15のいずれか一つが真」という意味

:-が先頭にくる場合は、制約であり、
:- not 15 = X + Y + Z, ...の場合、15 = X + Y + Zが必須条件になる。

参考

Coprisによる制約プログラミング入門
https://potassco.org/
https://qiita.com/yutaro-t/items/3a361aef5f9610ae4b8e

他の問題

ASP個人的ポータル

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0