Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@Ganesha

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

More than 1 year has passed since last update.

問題

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
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Ganesha

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?