i'am trying to solve a problem:
Given a string of N 0's and M 1's,how many unique permutations of this string start with 1?
answers for each test case is printed modulo(10^9 +7).
however my program takes too long to complete.
please suggest a much faster method.
Code:
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int T;
cin>>T;
string s;
int z,o;
long long ans;
while(T--)
{
s="";
ans=1;
cin>>z>>o;
for(auto i=0;i<o;++i)
s+='1';
for(auto i=0;i<z;++i)
s+='0';
while(prev_permutation(s.begin(),s.end()))
{
if(s[0]=='0')
break;
++ans;
}
cout<<ans%(1000000007)<<'\n';
}
}