Codeforces
CF Step
Youtube Linkedin Discord Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Code : Unconstrained Binary Strings

#include <bits/stdc++.h>
using namespace std;

const int mod = 998244353;

void inc(int &a, int b) {
    a += b;
    a %= mod;
}

void solve(int n) {
    vector<int> dp(n + 1);
    // dp[i] is the number of binary strings of length n

    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        // Append a zero
        inc(dp[i + 1], dp[i]);

        // Append a one
        inc(dp[i + 1], dp[i]);
    }

    cout << dp[n] << "\n";
}

int main() {
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        int n;
        cin >> n;
        solve(n);
    }
    return 0;
}