Error is: - /bin/run.sh: line 4: 18 Segmentation fault (core dumped) ./exe < run.stdin > run.stdout 2> run.stderr
Why is this showing error in CodingBlocksIDE
@aryangrover
hello aryan,
a) add a base case for n < 0 and return 0 in that case
b)

it should be n==m
c)

here u should make changes in first argument (i,e n ), second argument will remain same .
#include
using namespace std;
int count(int n,int m)
{
//Base Case
if(n==1)
{
return 1;
}
if(n==m)
{
return 2;
}
if(n<0)
{
return 0;
}
//Recursive Case
return count(n,n-1)+count(n,n-m);
}
int main() {
int t;
cin>>t;
for(int i=0;i<t;i++)
{
int n,m;
cin>>n>>m;
cout<<count(n,m)<<endl;
}
return 0;
}
Is It Okay now?
What to do in this case?
This was my code only.
It is still showing the error.
@aryangrover
check the last line i have changed that … also to pass all test case we need use dynamic programming
I don’t know anything about Dynamic Programming. I will have to use the Recursion only. By The Way can you tell me one thing, What I can in do in Dynamic Programming, It will take modulus of answer or anything else.
@aryangrover
by using dp we avoid number of computation by storing some useful information in array.
for now u can leave this problem. try again once u r done with dp
Sir There it is also given we have to take modulus with 10^9+7. I think I was missing that. I think now we can store that.
Ohkk Sir Then I think I should leave and move on to next
Sir Please tell me one more thing. Can You please check What are the questions of the Recursion only. Many questions are here of DP only. Whenever I check solution, they start taking towards DP Section. So Please help for that.
Means All the Problems in the Challenges of Recursion are of DP.
Tillling Problem 2
Generate Parenthesis
Count Number of Binary Strings
Friends Pairing Problem
Recursion-Codes of the String
Funky Chess Board
Class Assignment
Smart Keypad-1
Smart Keypad-Advanced
Tricky Permutations
No Same Permuations
Sum it Up
Expand the Pond
Minimum Time Traversal
Subset Sum Easy
Optimal Game Strategy 1
Optimal Game STrategy
Recursion Dictonary Order(Larger)
N-Knight Problem
N Queen Problem(Hard)
CROSSWORD
Robot Collect Points
Rat in a Maze

i think only these 3 are dp based problem .
but I think almost all problems have recursive solution so try to solve it using recursion . optimise them furthur after studying dp
Sir Even in Cases of Generate Parenthesis and Count number of Binary Strings, I don’t understand about the question, So saw the Hint but They were explained with DP only.
@aryangrover
a) recurrence relation of count binary is f(n) = f(n-1) +f(n-2) ( is this recurrence relation fimiliar to u). but for optimistaion u need dp
b) generate paranthesis has recursive solution .