Brownian Bears

시간 제한4초메모리 제한2048 MB

요약
n개 위치에서 두 곰이 매일 같은 확률로 이웃 칸으로 이동하거나 끝에서 머무를 때, d일 안에 두 곰이 같은 위치에서 먹이를 먹을 확률을 기약분수로 구한다.
난이도

보통10점 중 6점

유형
확률, 동적 계획법, 시뮬레이션, 수학
정답자
아직 제출이 없습니다

문제

Dr. Ursula Major is an internationally renowned expert in the study of bears, specifically brown bears, which are known in many parts of North America as grizzly bears. She is most famous for her discovery of an extremely rare brown bear subspecies --- the Brownian bear, whose feeding behavior seems to be guided by an intriguing mixture of regularity and randomness.

At present, Dr. Major is studying a pair of Brownian bears living on a narrow strip of land that is oriented east-west. This territory has nn evenly spaced locations where the bears can forage for berries, and Dr. Major has labelled these locations 1,2,…,n1, 2, \ldots, n from west to east. Every morning, each Brownian bear wakes up in one of the nn locations and randomly chooses to move either east or west to the neighboring location. What is remarkable is that the probability of moving in either direction is exactly 5050\\%! (Dr. Major's working theory is that this is rooted in some kind of quantum mechanical phenomenon in the bears' brains.) If a bear happens to start the day in one of the end locations (11 or nn), then it will randomly choose between moving to the sole neighboring location or staying where it is. After making its choice, the bear spends the day foraging for berries in the chosen location, and then also sleeps there that night. The next morning, the process begins all over again.

Dr. Major is particularly interested in days when the two bears forage together, i.e., in the same location, so she plans to observe them over a period of time, possibly as long as a month (or until her funding runs out). At the beginning of the first observation day, the two bears wake up in different locations. Can you help Dr. Major determine the probability that the two bears will forage together for at least one day during the course of her experiment?

Note that the two bears can move past each other without foraging together. For example, if the bears start a particular day in locations 44 and 55, and if the bear in location 44 moves east and the bear in location 55 moves west, then the bears simply pass each other that morning without foraging together.

입력

The input consists of a single line containing four integers, nn xx yy dd, where nn (2≤n≤100)(2 \leq n \leq 100) is the number of locations, xx and yy (1≤x,y≤n,x≠y)(1 \leq x, y \leq n, x \neq y) are the locations where the two bears wake up at the beginning of the first observation day, and dd (1≤d≤31)(1 \leq d \leq 31) is the number of observation days.

출력

Output a line containing the probability that the two bears forage together for at least one day during the dd observation days. Express this probability as a fraction a/ba/b in lowest terms, where aa is a non-negative integer and bb is a positive integer. See the sample outputs for examples.

예제3

  1. 예제 1

    입력
    4 1 2 2
    
    예상 출력
    3/8
    
  2. 예제 2

    입력
    6 2 5 2
    
    예상 출력
    0/1
    
  3. 예제 3

    입력
    2 1 2 1
    
    예상 출력
    1/2