File tree Expand file tree Collapse file tree 2 files changed +10
-18
lines changed
Expand file tree Collapse file tree 2 files changed +10
-18
lines changed Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 3192 KB, 시간: 0 ms
7+ 메모리: 2412 KB, 시간: 0 ms
88
99### 분류
1010
1111다이나믹 프로그래밍
1212
1313### 제출 일자
1414
15- 2025년 3월 30일 16:36:42
15+ 2025년 3월 31일 19:07:53
1616
1717### 문제 설명
1818
Original file line number Diff line number Diff line change 1- #include < iostream >
1+ #include < bits/stdc++.h >
22
33using namespace std ;
44
5- int dp [100001 ][ 3 ] ;
5+ int DP [100001 ] = { 1 , 3 } ;
66int mod = 9901 ;
77
88int main () {
9- int N;
10- cin >> N;
11- dp[0 ][0 ] = 1 ;
12- dp[0 ][1 ] = 1 ;
13- dp[0 ][2 ] = 1 ;
9+ int N;
10+ cin >> N;
1411
15- for (int i = 1 ; i < N; i++) {
16- dp[i][0 ] = (dp[i-1 ][1 ] + dp[i-1 ][2 ]) % mod;
17- dp[i][1 ] = (dp[i-1 ][0 ] + dp[i-1 ][2 ]) % mod;
18- dp[i][2 ] = (dp[i-1 ][0 ] + dp[i-1 ][1 ] + dp[i-1 ][2 ]) % mod;
19- }
12+ for (int i = 2 ; i <= N; i++) {
13+ DP[i] = (DP[i-2 ] + DP[i-1 ]*2 ) % mod;
14+ }
2015
21- const int answer = (dp[N-1 ][0 ] + dp[N-1 ][1 ] + dp[N-1 ][2 ]) % mod;
22- cout << answer << ' \n ' ;
23-
24- return 0 ;
16+ cout << DP[N];
2517}
You can’t perform that action at this time.
0 commit comments