Wednesday, 1 Dec 2021
Category: combionatrics

Given an array vec[] of size N of non-negative integers. The task is to count the number of subsequences with the sum equal to S – 2 where S is the sum of all the elements of the array.Examples:Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA […]

#include using namespace std;  int dp, choose;  int calc(int l, int r, string& s){          if (abs(r – l) % 2 == 0) {        return 0;    }      if (l > r) {        return dp[l][r] = 1;    }          if (dp[l][r] != -1) {        return dp[l][r];    }          if ((r – l) == 1) {        if (s[l] == s[r]) {            dp[l][r] = 1;        }        else {            dp[l][r] = 0;        }        return dp[l][r];    }          int ans = 0;    for (int k = […]

#include using namespace std;  int calculate(int position, int used, int unused, int P,              int M, vector& dp){        if (position == P) {                        return unused == 0 ? 1 : 0;    }              if (dp[position][used][unused] != -1)        return dp[position][used][unused];          int result = 0;              if (unused > 0) {                        result += calculate(position + 1, used + 1,                            unused – 1, P, M, dp)                  * unused;    }              if (used > M) {                        result += […]

Given a string S consisting of N digits and an integer K, the task is to count the number of ways to remove digits from the number formed by the concatenating the string S, K number of times, such that the resulting string is divisible by 5. Since count can be very large, so print […]