### codenote's blog

By codenote, history, 3 weeks ago, ,

You are given a string of length n and two alphabets x and y . There are q queries each has 2 integers l and r.you have to consider substring [l,r] of given string and count the number of distinct sub sequence of sub string which starts with x and ends with y.
Two substring are considered different if they starts and end with different indices.
count the number mod 1e7.
example
aabb
a b
0 2 ans = 3
1 3 ans=3
0 3 ans = 9

•
• -2
•

By codenote, history, 2 months ago, ,

What is good approach to merge sorted files. I have around 10k files of size 1-2 mb and want to merge them in single sorted file.

•
• -2
•

By codenote, history, 3 months ago, ,

I want to know different problem solving techniques and algorithms.
Is spoj good to learn different approach and algorithms ?
If any other source helped you than please tell.I don't want to waste time on adhoc problems.
Note: I know that many people ask such question and i read them also but still i have doubts so posted

•
• -4
•

By codenote, history, 3 months ago, ,

In this problem you are given "x" amount of money in currency "s" and you want to maximise the amount in "m" steps to currency "f". cost matrix is given for transfer rate. Sounds similar to finding number of ways to reach from one node to another in k steps. So the answer to problem is (s,f) value of mth power of given cost matrix (exchange rate matrix). we need to modify matrix multiplication accordingly to get maximum cost.

code

But we want ans%mod , this mod will ruin my multiplication of matrix. I will not get maximum. Editorial suggest to use power of primes , can someone please explain that.

•
• +5
•

By codenote, history, 4 months ago, ,

Your task is to find total number strings of length N consisting of {X,Y} with the following condition
a) It does not have leading "X" letter.
b) It does not contain P consecutive "X" letters.
`N<10^4 and P<11`
I am unable to form recurrence of this dp problem. can someone please explain the recurrence in an easy way.
I was thinking about dp[i][j] as number of strings of length i ending with j 'X' , but not able to come up with transition.
Thanks.

•
• -5
•

By codenote, history, 5 months ago, ,

How to solve this problem using binary search.
Problem Statement :
You are given an array A of N integers in nondecreasing order. Remove K integers such that the maximum difference between two consecutive elements is minimized.
solution using binary search (I am not getting its intuition). ​​

•
• +5
•

By codenote, history, 6 months ago, ,

Today i was solving Ktree and i came with this solution. This solution gave me TLE. This is most obvious solution which anyone can think and code. Now i don't see any repetitive states in this solution to memoize .Am i missing something ? Or if i am going wrong then please tell your recursive approach.

``````#include <bits/stdc++.h>
using namespace std;
const int N = 1234567;
const int mod = 1e9+7;
typedef long long ll;
#define mp make_pair
#define pb push_back
ll n,k,d;
ll solve(ll sum,ll seen)
{
if(sum==n and seen==1)
return 1;
if(sum>n  or (sum==n and !seen) )
return 0;

ll ans=0;
for(int i=1;i<=k;i++)
{
if(i>=d)
seen=1;

ans+=solve(sum+i,seen);
}
return ans;
}
int main()
{
ios_base:: sync_with_stdio(false); cin.tie(0);
// freopen ("inp","r",stdin);
// freopen ("out","w",stdout);
cin>>n>>k>>d;
cout<<solve(0,0);
return 0;
}
``````