티스토리 뷰
문제링크
https://www.acmicpc.net/problem/11057
11057번: 오르막 수
오르막 수는 수의 자리가 오름차순을 이루는 수를 말한다. 이때, 인접한 수가 같아도 오름차순으로 친다. 예를 들어, 2234와 3678, 11119는 오르막 수이지만, 2232, 3676, 91111은 오르막 수가 아니다. 수�
www.acmicpc.net
N이 1일 때는 0~9 까지 10가지 방법이 있습니다.
N이 2이상일 때는 0~9까지 가장 오른쪽 숫자보다 작거나 같은 숫자들의 방법을 모두 더한 값입니다.

예를들어
N이 3일 때 마지막 숫자가 1이면 001, 011, 111로 3가지가 나오고
마지막 숫자가 2이면 002, 012, 112, 122, 222로 5가지가 나옵니다.
이러한 방법으로 마지막 숫자가 0~9일때 나올 수 있는 모든 방법의 합이 정답이 됩니다.
구현 코드
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> | |
#define endl '\n' | |
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr); | |
using namespace std; | |
int d[1001][10]; | |
int main(){ | |
fastio; | |
int n; | |
cin >> n; | |
for(int j=0;j<10;j++) | |
d[1][j] = 1; | |
for(int i=2;i<=n;i++){ | |
for(int j=0;j<10;j++){ | |
for(int k=0;k<=j;k++){ | |
d[i][j] += d[i-1][k]; | |
} | |
d[i][j] %= 10007; | |
} | |
} | |
int sum = 0; | |
for(int i=0;i<10;i++) | |
sum += d[n][i]; | |
cout << sum % 10007 << endl; | |
return 0; | |
} |
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
n = int(input()) | |
dp = [[0 for i in range(10)] for j in range(1001)] | |
for j in range(0,10): | |
dp[1][j] = 1 | |
for i in range(2,n+1): | |
for j in range(10): | |
for k in range(j+1): | |
dp[i][j] += dp[i-1][k] | |
dp[i][j] %= 10007 | |
print(sum(dp[n]) % 10007) |
'Coding Test > 백준' 카테고리의 다른 글
[C++/Python] 백준 9465 - 스티커 (0) | 2020.07.29 |
---|---|
[C++/Python] 백준 2193 - 이친수 (0) | 2020.07.28 |
[C++/Python] 백준 10844 - 쉬운 계단 수 (0) | 2020.07.24 |
[C++/Python] 백준 9095 - 1, 2, 3 더하기 (0) | 2020.07.23 |
[C++/Python] 백준 11727 - 2xn 타일링 2 (0) | 2020.07.22 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 두니발 박사의 탈옥
- 출전 순서 정하기
- 삼각형 위의 최대 경로 수 세기
- hive
- Jaeha's Safe
- microwaving lunch boxes
- Sqoop
- 하이브
- 외발 뛰기
- 합친 lis
- 스파크
- 팰린드롬 구하기
- 배열과 문자열
- 2225
- HDFS
- 백준
- HiveQL
- Hadoop
- 완전탐색
- 코딩인터뷰 완전분석
- 종만북
- import
- 분할정복
- python
- 하둡
- C++
- 알고스팟
- 삼각형 위의 최대 경로
- pyspark
- Django
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함