2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Project Euler 31

Last updated at Posted at 2015-03-03

問題

イギリスでは硬貨はポンド£とペンスpがあり,一般的に流通している硬貨は以下の8種類である.

1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).

以下の方法で£2を作ることが可能である.

1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p

これらの硬貨を使って£2を作る方法は何通りあるか?
http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2031

回答

再帰使えってっことですね。わかります。

def count_methods(target, coins):
  if len(coins) == 0:
    return 1
  else:
    s = 0
    c = coins[0]
    q = (target // c) + 1
    for i in range(0,q):
      s += count_methods(target - c * i, coins[1:])
    return s
    
def main():
  TARGET = 200
  COINS = [200,100, 50, 20, 10, 5, 2]
  print count_methods(TARGET,COINS)

main()
2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?