Given a String S which consists of only binary numbers(i.e.,0's and 1's), you have to find the number of unique ways that the string can be permuted starting with '1'.
For Example:
Let Number of 1's denoted as 'N' & Number of 0's denoted as 'M'
If N=1 & M=1, the possible permutations are 01 & 10
Here, the string that start with '1' is "10". So, the Output is 1
Method 1:
Implementation:
//Following is the C++ implementation to find the count of unique permutations of the string that starts with '1'.
//Following is the 'C' Implementation to find the number of unique ways that the string is permuted starting //with '1
For Example:
Let Number of 1's denoted as 'N' & Number of 0's denoted as 'M'
If N=1 & M=1, the possible permutations are 01 & 10
Here, the string that start with '1' is "10". So, the Output is 1
Method 1:
Implementation:
//Following is the C++ implementation to find the count of unique permutations of the string that starts with '1'.
#include <iostream> using namespace std; int fact(int N) { if(N==1) return 1; if(N==0) return 1; return N*fact(N-1); } int main() { int T; cin>>T; int N,M; while(T--) { cin>>N>>M; int ncr= (fact(M+N-1)) / ((fact(M-1)) * fact(N)); cout<<ncr<<"\n"; } return 0; }
//Following is the 'C' Implementation to find the number of unique ways that the string is permuted starting //with '1
#include <stdio.h> int fact(int N) { if(N==1) return 1; if(N==0) return 1; return N*fact(N-1); } int main() { int T,N,M; scanf("%d",&T); while(T--) { scanf("%d %d",&N,&M); int ncr= (fact(M+N-1)) / ((fact(M-1)) * fact(N)); printf("%d\n",ncr); } return 0; }