Code wrong count subsequences

#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>> t;
while(t–)
{

	string s;
	cin>> s;
	set<string> pp;
	int l=s.length();
	cout<<l<<endl;
	for(int i=0;i<l;i++)
      {
		  for(int j=i;j<l;j++)
		  {
			  string r=s.substr(i,j);
			  pp.insert(r);
		  }
	  }
	  int k=1;
	  for(auto it=pp.begin();it!=pp.end();it++)
	  {
		  cout<<*it<<endl;
		  k++;
	  }
	  cout<<k<<endl;
}
return 0;

}

Hey @sunneykumar309 please share your code using ide.codingblocks.com

Debugging your code, please be patient.

source.cpp:6:9: warning: null character(s) ignored
6 | while(tb )
| ^
source.cpp:6:10: error: stray ‘\23’ in program
6 | while(tb )
| ^
source.cpp: In function ‘int main()’:
source.cpp:6:7: error: ‘tb’ was not declared in this scope; did you mean ‘t’?
6 | while(tb )
| ^~
| t

now i am getting this error


The error was in while condition, it should have been t-- instead of t-

how to approach this q
my approach is wrong because it gives only susstring

substring not the subsequences

Tell me are you familiar with the concept of recursion?

yes i am but still while using

So , this question will be solved by using concept of dp , so I want you to tell me that do you want me tell you Dp approach or first you will do it yourself and then ask for help?

recursion .
Can you please me tell me how to be perfect at Dp and recursion.

Practice as much questions of dp and recursion. First do all the questions of your course on this topic , then go on leetcode and hackerrank for more questions.

There would be an explanation video in your course name Subsequences Generation Recursion . It will give you a better explanation.

can you please tell me atleast how many q should i do.

Bro don’t go with quantity, go with quality. Unless and until you don’t get an idea of how dp works. Try different different questions. You getting me?

yes.i want to practice a lot’s of question but once i stuck and i have no idea that how to approach then what should i do ? Is moving a good decision.

Until you have TA support you can post your question here as a doubt in which you will face problem. All TA’s are good , they will help you in approach as well as in debugging your code :slight_smile:

1 Like

now i am in second year how much time should i give in a question.
1 day,2 day or couple of hours

Couple of hours would be enough.

1 Like