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 4
4
5
5
### 성능 요약
6
6
7
- 메모리: 3192 KB, 시간: 0 ms
7
+ 메모리: 2412 KB, 시간: 0 ms
8
8
9
9
### 분류
10
10
11
11
다이나믹 프로그래밍
12
12
13
13
### 제출 일자
14
14
15
- 2025년 3월 30일 16:36:42
15
+ 2025년 3월 31일 19:07:53
16
16
17
17
### 문제 설명
18
18
Original file line number Diff line number Diff line change 1
- #include < iostream >
1
+ #include < bits/stdc++.h >
2
2
3
3
using namespace std ;
4
4
5
- int dp [100001 ][ 3 ] ;
5
+ int DP [100001 ] = { 1 , 3 } ;
6
6
int mod = 9901 ;
7
7
8
8
int 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;
14
11
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
+ }
20
15
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];
25
17
}
You can’t perform that action at this time.
0 commit comments