티스토리 뷰
문제 링크
https://algospot.com/judge/problem/read/SNAIL
algospot.com :: SNAIL
달팽이 문제 정보 문제 깊이가 n 미터인 우물의 맨 밑바닥에 달팽이가 있습니다. 이 달팽이는 우물의 맨 위까지 기어올라가고 싶어하는데, 달팽이의 움직임은 그 날의 날씨에 좌우됩니다. 만약 �
algospot.com
1. 현재날짜+1에서 한칸 더 올라가는 경우 * 0.25
2. 현재날짜+2에서 두칸 더 올라가는 경우 * 0.75
두가지 경우를 더해주면 값을 구할 수 있습니다.
구현 코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
#include <iomanip> | |
#define endl '\n' | |
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr) | |
using namespace std; | |
const int MAX = 1001; | |
int n, m; | |
double cache[MAX][MAX]; | |
double climb(int days, int climbed){ | |
//m일이 지났을 때 n칸을 올라온 경우 1, 그렇지 않은 경우 0을 반환한다. | |
if(days == m) return climbed >= n ? 1 : 0; | |
double &ret = cache[days][climbed]; | |
if(ret != -1) return ret; | |
return ret = 0.25 * climb(days+1, climbed+1) + 0.75 * climb(days+1, climbed+2); | |
} | |
int main(){ | |
fastio; | |
int _; | |
cin >> _; | |
while(_--){ | |
fill_n(cache[0], MAX*MAX, -1); | |
cin >> n >> m; | |
cout << fixed; | |
cout.precision(10); | |
cout << climb(0,0) << endl; | |
} | |
return 0; | |
} |
'Coding Test > 알고스팟' 카테고리의 다른 글
[C++] 알고스팟/동적계획법 - 두니발 박사의 탈옥 (0) | 2020.08.26 |
---|---|
[C++] 알고스팟/동적계획법 - 폴리오미노 (0) | 2020.08.25 |
[C++] 알고스팟/동적계획법 - 삼각형 위의 최대 경로 수 세기 (0) | 2020.08.23 |
[C++] 알고스팟/동적계획법 - 타일링 (0) | 2020.08.22 |
[C++] 알고스팟/동적계획법 - Quantization (0) | 2020.08.21 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Jaeha's Safe
- Hadoop
- 분할정복
- 하둡
- 하이브
- 코딩인터뷰 완전분석
- 합친 lis
- 출전 순서 정하기
- 스파크
- import
- microwaving lunch boxes
- 백준
- HDFS
- Sqoop
- 팰린드롬 구하기
- 배열과 문자열
- 완전탐색
- pyspark
- 삼각형 위의 최대 경로 수 세기
- 외발 뛰기
- C++
- 종만북
- 두니발 박사의 탈옥
- 삼각형 위의 최대 경로
- python
- 2225
- Django
- HiveQL
- 알고스팟
- hive
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함