78852024-01-11 17:56:15adamJárda-L (40)cpp17Accepted 40/403ms4184 KiB
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> dp;

int calculate (int n, int space) {
    if (n < 0)  return 0;
    else if (n == 0 && space == 0) return 1;


    if (dp[n][space] != -1) return dp[n][space];
    int answer = 0;
    if (space == 2) {
        answer += calculate(n, 0); // fektettett
    } else if (space == 1) {
        answer += calculate(n-1, 1); // fektetett
        answer += calculate(n-1, 0); // L
    }else if (space == 0) {
        answer += calculate(n - 1, 0); // allitott
        answer += calculate(n - 2, 2); // fektettett
        answer += calculate(n - 2, 1) * 2; // L
    }

    return dp[n][space] = answer;
}

int main() {
    int n;
    cin >> n;
    dp.assign(n+1, vector(3, -1));

    cout << calculate(n, 0) << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1808 KiB
2Accepted0/03ms2204 KiB
3Accepted2/23ms2344 KiB
4Accepted2/23ms2488 KiB
5Accepted2/23ms2648 KiB
6Accepted2/23ms2860 KiB
7Accepted2/23ms3088 KiB
8Accepted3/33ms3236 KiB
9Accepted3/33ms3360 KiB
10Accepted3/33ms3532 KiB
11Accepted3/33ms3620 KiB
12Accepted3/33ms3640 KiB
13Accepted3/33ms3852 KiB
14Accepted3/33ms3944 KiB
15Accepted3/33ms4048 KiB
16Accepted3/33ms4052 KiB
17Accepted3/33ms4184 KiB