angry_pikachu's blog

By angry_pikachu, history, 15 months ago,

Source — Link

Given a string with lowercase letters and “?” where each “?” can be replaced by any lowercase character, find the total number of strings such that the first and last characters are the same and no adjacent characters are the same.

I am still new to DP, help would be appreciated

• +6

By angry_pikachu, history, 18 months ago,

I am getting error

118 | for(ll it: nde[i]) dfs(it,fren[i]);

In this code , ll means long long, nde[i] is a vector of int

auto dfs = [&](int i,int x)->void{
fren[i]+=x;
for(ll it: nde[i]) dfs(it,fren[i]);
};
dfs(0,0);


Writing a blog in codeforces for first time

C++ 17 online compiler

Worked using

    function<void(int, int)> dfs = [&](int i, int x) -> void {
fren[i] += x;
for (ll it : nde[i])
dfs(it, fren[i]);
};


Also by changing vector<int> nde[n] to vector<vector<int>> nde(n) and by using the function

    auto dfs = [&](int i,int x, auto &&dfs)->void{
fren[i]+=x;
for(ll it: nde[i]) dfs(it,fren[i], dfs);
};
dfs(0,0,dfs);

• -21