問題一覧 > 通常問題

No.560 Mysterious Knapsack

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 小数誤差許容問題 絶対誤差または相対誤差が $10^{-8}$ 以下。ただし、ジャッジ側の都合で500桁未満にしてください
タグ : (AC するまで非表示) / 解いたユーザー数 301
作問者 : りあん / テスター : Nafmo2
お気に入りにしたユーザー ProblemId : 1150 / 自分の提出
問題文最終更新日: 2026-06-26 06:07:05
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 172 (順位表) の他の問題:

Problem Statement

Ooka, who lives in the Great Okayama Empire, can use magic.

Being able to use magic, Ooka heard a rumor about a mysterious pocket that, when tapped while containing $M$ biscuits, makes the number of biscuits inside $M + 1$, and he decided to try making something similar himself.

However, he thought that he wouldn't be all that happy no matter how many biscuits he got, and that increasing them only one at a time was inefficient... So, after much trial and error, he succeeded in making the following knapsack that increases money.

When the knapsack contains $M$ yen and is tapped once,

  • with probability 1/3, its content becomes $M \times 2$ yen
  • with probability 1/3, its content becomes $M + 1$ yen
  • with probability 1/3, its content becomes $0$ yen

(The result of each trial is independent, regardless of the results before and after it, the state of the content, and so on.)

However, Ooka became very worried about whether he could actually increase his money using this knapsack.

So, for Ooka's sake, find the expected value of the amount of money in the knapsack after tapping a knapsack that initially contains $M$ yen exactly $N$ times.

Input

$M$ $N$

The amount $M$ initially in the knapsack and the number of times $N$ the knapsack is tapped are given on one line, separated by a space.

All inputs are integers and satisfy the following constraints.

  • $0 \leq M, N \leq 1000$

Output

Output the amount of money in the knapsack after tapping it exactly $N$ times.

An error of at most $10^{-8}$ is allowed.

Print a newline at the end.

Sample

Sample 1
Input
100 2
Output
100.666666666667

When a knapsack containing 100 yen is tapped twice, it ends up with one of 400 yen, 201 yen, 0 yen, 202 yen, 102 yen, 0 yen, 0 yen, 1 yen, 0 yen, with equal probability.

Sample 2
Input
0 30
Output
10

Ooka is an excellent magician, so he can create money even from a state of 0 yen.

Sample 3
Input
114 514
Output
285.333333333333

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。