LoginSignup
0
0

More than 3 years have passed since last update.

AtCoder ABC 114 C - 755をPython3で解いた

Posted at

AtCoderの 755 というC問題をPythonで解いてみました。再帰関数を使うと解きやすい問題です。

日本の競技プログラミング界では言わずと知れたけんちょんさんの記事を参考にしました。
参考記事:https://drken1215.hatenablog.com/entry/2019/04/03/125400

まだよわよわなので、論理演算子とビット演算子の違いの理解に苦労しました。
これらの理解に助かった記事はこちら↓
http://ings.sakura.ne.jp/prog/bitoperator.html

N = int(input())

def func(cur, use, counter):
  if cur > N: return
  if use == 0b111: counter.append(1)  # 答えを増やす

  # 7を付け加える
  func(cur * 10 + 7, use | 0b001, counter)
  # 5を付け加える
  func(cur * 10 + 5, use | 0b010, counter)
  # 3を付け加える
  func(cur * 10 + 3, use | 0b100, counter)

res = []
func(0, 0, res)
print(sum(res))

結果はこんな感じです。無事にACできました。
Screen Shot 2020-05-10 at 13.42.52.png

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