-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include <bits/stdc++.h> | ||
|
||
const int MOD = 10000; | ||
int n, k; | ||
|
||
int dp[101][4][3]; | ||
int selected[101]; | ||
|
||
void getinput() | ||
{ | ||
std::cin >> n >> k; | ||
for (int i = 0; i < k; i++) | ||
{ | ||
int a, b; | ||
std::cin >> a >> b; | ||
selected[a] = b; | ||
} | ||
} | ||
|
||
// 오늘은 day이고, 어제 prev를 먹었다. 연속해서 먹은 횟수는 streak. | ||
int solve(int day, int prev, int streak) | ||
{ | ||
if (streak == 3) | ||
return 0; | ||
auto &ret = dp[day][prev][streak]; | ||
if (ret != -1) | ||
return ret; | ||
if (day == n) | ||
return ret = (streak < 3); | ||
|
||
ret = 0; | ||
if (selected[day]) | ||
{ | ||
if (prev == selected[day] && streak == 2) | ||
return ret = 0; | ||
auto next_streak = (prev == selected[day] ? streak + 1 : 1); | ||
return ret = solve(day + 1, selected[day], next_streak); | ||
} | ||
else | ||
{ | ||
for (int i = 1; i <= 3; i++) | ||
{ | ||
// day에 i번 파스타를 먹음 | ||
auto next_streak = (prev == i ? streak + 1 : 1); | ||
ret = (ret + solve(day + 1, i, next_streak)) % MOD; | ||
} | ||
return ret; | ||
} | ||
} | ||
|
||
int solve() | ||
{ | ||
std::memset(dp, -1, sizeof(dp)); | ||
if (selected[1]) | ||
{ | ||
int ans = solve(2, selected[1], 1); | ||
return ans; | ||
} | ||
else | ||
{ | ||
int ans = 0; | ||
for (int i = 1; i <= 3; i++) | ||
{ | ||
ans = (ans + solve(2, i, 1)) % MOD; | ||
} | ||
return ans; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
std::ios::sync_with_stdio(false); | ||
std::cin.tie(0); | ||
|
||
getinput(); | ||
std::cout << solve() << '\n'; | ||
} |