시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
10 초 128 MB 196 84 66 48.889%

문제

걷기 전에 동전을 던진 다음, 앞 면이면 왼쪽으로 한 칸, 뒷 면이면 오른쪽으로 한 칸 이동하는 방법을 랜덤 걷기라고 한다. 이 랜덤 걷기의 위치의 기대값은 항상 0이 된다. 즉, 랜덤 걷기를 아무리 많이 한다고 해도, 결국에는 처음 시작한 곳으로 돌아오게 되는 것이다.

랜덤 걷기에서 왼쪽으로 갈 확률과 오른쪽으로 갈 확률, 그리고 동전을 던지는 횟수가 주어졌을 때, 가장 오른쪽 위치의 기대값을 구하는 프로그램을 작성하시오.

입력

첫째 줄에는 테스트 케이스의 P가 주어진다. 각 테스트 케이스는 모두 독립적이다.

각 테스트 케이스는 한 줄로 이루어져 있다. 이 줄에는 총 세 개의 숫자가 주어지는데, 왼쪽부터 순서대로 n, L, R이다. n(1 ≤ n ≤ 1000)은 동전을 던지는 횟수이다. L과 R은 각각 왼쪽으로 갈 확률과 오른쪽으로 갈 확률이다. ( 0 ≤ L ≤ 1, 0 ≤ R ≤ 1, 0 ≤ L+R ≤ 1) 이 문제에서 사용하는 동전은 조금 독특해서, 앞 면과 뒷 면이 나올 확률이 서로 다를 수도 있다. 또, 1-L-R은 동전의 옆 면이 나올 확률로, 옆 면이 나온 경우에는 그 자리에 그대로 있는다.

출력

각 테스트 케이스에 대해서, 가장 오른쪽 위치의 기대값(평균)을 소수점 넷째 자리 까지 출력한다.

예제 입력 1

4
1 0.5 0.5
4 0.5 0.5
10 0.5 0.4
1000 0.5 0.4

예제 출력 1

0.5000
1.1875
1.4965
3.9995
W3sicHJvYmxlbV9pZCI6IjM5NDYiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWI3OWNcdWIzNjQgXHVhYzc3XHVhZTMwIiwiZGVzY3JpcHRpb24iOiI8cD5cdWFjNzdcdWFlMzAgXHVjODA0XHVjNWQwIFx1YjNkOVx1YzgwNFx1Yzc0NCBcdWIzNTh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