Notice
														
													
												
											
												
												
													Recent Posts
													
											
												
												
													Recent Comments
													
											
												
												
											
									| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 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 | 
													Tags
													
											
												
												- STL
- 백준
- 삼성SW테스트
- 삼성
- 코딩스킬
- 완전탐색
- dfs
- 모의SW역량테스트
- substr
- Map
- 브루트포스
- 문자열
- 백트래킹
- 2018
- swea
- Set
- find
- 프로그래머스
- 삼성SW역량테스트
- 시뮬레이션
- priority_queue
- 레벨3
- 이런게4문제
- KAKAO
- dp
- Sort
- C++
- 코딩테스트
- BFS
- 레벨2
													Archives
													
											
												
												- Today
- Total
-
[DP] BOJ - 10844번 (쉬운계단수) 본문
https://www.acmicpc.net/problem/10844
10844번: 쉬운 계단 수
첫째 줄에 정답을 1,000,000,000으로 나눈 나머지를 출력한다.
www.acmicpc.net
백준 DP 연습문제다.
끝 자리에 유의해서 DP[자리수][끝자리수]로 만들 수 있는 계단수를 찾으면 된다.
수가 매우 커지기 때문에 모듈러 연산을 위해 long long에 정답을 저장해야 하며,
동작과정 중 n을 만나면 계산해둔 값을 이용해 답을 출력한뒤 종료하도록 구현했다.
| 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 31 32 33 34 35 36 37 38 39 | #include <stdio.h> #pragma warning(disable:4996) #define div 1000000000 int main(){     long long DP[101][10];     DP[1][0] = 0;     for (int c = 1; c < 10; c++) DP[1][c] = 1;     int n;     scanf("%d", &n);     if (n == 1){         printf("9\n");         return 0;     }     for (int r = 2; r <= 101; r++){         for (int c = 0; c <= 9; c++){             if (c == 0){                 DP[r][c] = DP[r - 1][1];                 DP[r][c] = DP[r][c] % div;             }             else if (c == 9){                 DP[r][c] = DP[r - 1][8];                 DP[r][c] = DP[r][c] % div;             }             else{                 DP[r][c] = DP[r - 1][c - 1] + DP[r - 1][c + 1];                 DP[r][c] = DP[r][c] % div;             }         }         if (r == n){             long long ret = 0;             for (int c = 0; c <= 9; c++) {                 ret += DP[r][c]; // 모두 더한다음에 모듈러해준다.             }             printf("%lld\n", ret%div);             break;         }     }     return 0; } http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter | http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs | 
'5. DP' 카테고리의 다른 글
| [DP] 백준 2011번 - 암호코드 (0) | 2020.01.29 | 
|---|---|
| [DP] BOJ 11057번 - 오르막 수 (0) | 2020.01.29 | 
| [DP] 백준 4811번 - 알약 (0) | 2020.01.28 | 
| [DP] 백준 5557번 - 1학년 (0) | 2020.01.27 | 
| [DP] 백준 2193번 - 이친수 (0) | 2020.01.08 | 
			  Comments
			
		
	
               
           
					
					
					
					
					
					
				