시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
10 초 128 MB 337 158 106 47.321%

문제

걷기 전에 동전을 던진 다음, 앞 면이면 왼쪽으로 한 칸, 뒷 면이면 오른쪽으로 한 칸 이동하는 방법을 랜덤 걷기라고 한다. 이 랜덤 걷기의 위치의 기댓값은 항상 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
W3sicHJvYmxlbV9pZCI6IjM5NDYiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWI3OWNcdWIzNjQgXHVhYzc3XHVhZTMwIiwiZGVzY3JpcHRpb24iOiI8cD5cdWFjNzdcdWFlMzAgXHVjODA0XHVjNWQwIFx1YjNkOVx1YzgwNFx1Yzc0NCBcdWIzNThcdWM5Y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RhIHNldCBudW1iZXIsIGZvbGxvd2VkIGJ5IGEgc2luZ2xlIHNwYWNlIHdoaWNoIGlzIHRoZW4gZm9sbG93ZWQgYnkgdGhlIGV4cGVjdGVkIChhdmVyYWdlKSByaWdodG1vc3QgcG9zaXRpb24geW91IHdpbGwgb2J0YWluIGR1cmluZyB0aGUgd2FsaywgYXMgYSBkb3VibGUgcHJlY2lzaW9uIGZsb2F0aW5nIHBvaW50IHZhbHVlIHRvIGZvdXIgZGVjaW1hbCBwbGFjZXMuPFwvcD5cclxuIiwiaGludCI6IiIsIm9yaWdpbmFsIjoiMSIsInByb2JsZW1fbGFuZ19jb2RlIjoiXHVjNjAxXHVjNWI0In1d

출처

ACM-ICPC > Regionals > North America > Greater New York Region > 2012 Greater New York Programming Contest D번