Let's get any subsequence. For every occurence of s in that subsequence of F(x), we'll increase the answer by 1. Instead, for every possible occurence we can increase the answer by number of subsequences that have that substring in it. Let's consider a subsequence i1, i2...., in (indices of F(x)) such that if we concatenate the characters at such index, we would obtain s. It means that in every following subsequence we should update the answer by 1.

For any j that is equal to some ik, it must contain it.

For any j that isn't equal to some ik but i1 < j < in, it can't contain it.

For any j < i1 or j > in, it can contain it, so we have 2 possibilities.

So, for every set of indices (called i) we can increase the answer by 2i1 - 1 + n - in and we can obtain the answer.

Let's create a function f(l, r, x) which is equal to answer when we are search for s[l..r] in F(x). (Not exactly but we'll come to that later.) F(x) is equal to F(x - 1)F(x - 2) so, that substring could be in F(x - 1), F(x - 2) or divided in both. If it's in F(x - 1), it means that we should calculate the number of ways and get the answer. Here's the key point, if r equals to n it means that we won't get anything from right so we should multiply it by 2|(F(x - 2)|.

Since 2x * 2y = 2x + y in the end we will get the each occurence multiplied by 2n - in. When we will handle the l = 1 cases, similarly, we will get the answer.

I've seen your code. There's "ret = add(ret, mul(f(l, k, x — 1), f(k + 1, r, x — 2)));". Why can they be simply multiplied? I think that f(l,k,x-1) may contain some subsequence like ...l,t... , and so to f(k+1,r,x-2). ...l,t... concatenate ...t+1,r... is ...l,t......t+1,r..., but not ...l,t,t+1,r... . How are those .... between l,t and t+1,r considered?

OK I got it. "which is equal to answer when we are search for s[l..r] in F(x)", This value depends on whether l==1 or r==n. If l==1 and r==n, it represent ...l,r... ; If l==1 and r<n , it represent ...l,r ; If l>1 and r==n, it represent l,r... ; If l>1 and r<n , it represent l,r .

I'm most probably missing something obvious, but why would greedy not work on Problem 946D ?

Like In O(mn) time, create an n*2 array greedy[day][i] where if there's still atleast one 1 in the ith string, then let greedy[i][0] denotes the number of hours that would reduce if you skip the first class in day i, and let greedy[i][1] denote the number of hours that would reduce if you skip the last class in day i (these two have same values if on that day, we have only one class), and if day i has no class, then set greedy[i][0] = greedy[i][1] = - ∞

Then initialize an heap with those n*2 elements in time. Then at each step, I pick the largest element from the heap in time, say it's greedy[j][1], and I change the last 1 in day i to 0, and update greedy[j][0] and greedy[j][1] in the heap. I stop when I have picked k elements.

I have a question about 946D. The problem statement was not clear to me. 2 6 2 010010 111100 For above example, I thought answer is 3. But, Passed code's answer is 4. It means skipped lessons is based on day, not week.

Can anyone plz explain the idea of this code http://codeforces.com/contest/946/submission/36016439 ? It's Problem F. I can't grasp the DP transition in this code clearly. As far as I studied, I guess it maybe use some math to simplify the transition. Can anyone help plz?

Problem G can be solved with similar method as in the editorial, but without using segment tree. Let's calc dp[cnt][len] — minimum element ending sequence with cnt bad elements with length len. Calculating is similar to finding longest increasing sequence : for 1 bad element we use binary search for x-i+1, for 0 x-i.

Brief Idea -LNDS — Longest Non-decreasing SubsequenceA[i] = A[i] — i for every 'i'For every index 'i', we want the length of LNDS ending at 'i-1', say E[i-1], and the length of LNDS from [i+1, n] whose 1st element is greater than A[i-1], say S[i+1]. We can easily calculate S[i+1] using segment tree. Calculation of E[i-1] is trivial.

Have a char variable C which is intitially equal to 'a'.You need to check if there exists a subsequence of the English Alphabet in the given string. So iterate through the string fully, for each iteration check if the current character of string is not greater than C and increment C. So in the end, if your C value is not equal to 'z', then it means you don't have a subsequence of the English Alphabet. Hope this helps :)

For question C, I understand how this: aacceeggiikkmmooqqssuuwwyy becomes: abcdefghijklmnopqrstuvwxyz

However, I do not understand why the check is only if the current character is not greater than variable C.

I do not understand why this: aada becomes: abdc

Why does the final character become c from a? The impression I got from the question is that a character can only move to the next character in the alphabet (a -> b, f -> g etc). Given this it seems that the final character could only become b.

It'll choose the second string as it has a 0 nearer to 1 so in the second skipped lesson the string becomes: 1111000 but if it chooses the first string, it will become: 1110100 hence less time saving. That's how my pq works.. what's wrong ?

losmi247, my solution uses an array that I call opt[i][j], wich is the minimun amount of hours you have to spend in the i-th day if you kick off exactly j classes that day. That is the mn[i][j]. This can be done greedly by taking the best prefix and suffix of lessons of that day such len(prefix)+len(suffix)==j. Then you can do dp[i][j] = min(dp[i][j], dp[i-1][j-k] + opt[i][k]);

PD: if the number of lessons you going to skip the i-th day is greater or equal than the number of lessons you have to attend that day opt[i][j] should be 0

Please explain me problem F. Considering test 1:- 2 4 11 Judge answer is 14. But, I thought of problem as creating fibonacci string of 4 that is F(4) which is equal to 10110, then finding cost that is number of time string s that is 11 (entered by user) contained in F(4).

So, my answer comes out to be 1(int) as 11(string) is contained only one time is F(4) i.e. 10110(string).

I wonder if my solution works ? If not, please explain and give example(s). Thanks in advance :D

For each step i, I store 2 strings pre and suf that is the prefix and suffix of F[i]. Each string's length is smaller than the length of the given string s. With this, at each step I can string match to find new occurences that appears due to the concatenation of F[i] and F[i — 1]. In addition, I notice that F[i]'s pre = F[i — 1]'s pre and F[i]'s suf = F[i — 2]'s suf.