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

Community
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@Ganesha

# ASP 例題１ コイン問題（制約充足問題）

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`が必須条件になる。

# 他の問題

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