LoginSignup
0
0

More than 3 years have passed since last update.

[Python]bit全探索 ABC045C,ARC061C

Last updated at Posted at 2020-12-06

ABC045C

$2^n$通りを探索する場合は、bit全探索が便利である。

下は、けんちょんさんのビット演算のまとめ表
image.png
Python ビット演算 超入門

サンプルコード
s = input()
n = len(s)

ans = 0

for bit in range(1 << (n - 1)): # n-1左シフト
    f = s[0]

    for i in range(n - 1):
        # フラグが立っている所に+を挿入
        if bit & (1 << i):
            f += "+"
        f += s[i + 1]

    ans += sum(map(int, f.split("+")))

print(ans)
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