-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathNumberOfPaths.cpp
More file actions
35 lines (34 loc) · 822 Bytes
/
NumberOfPaths.cpp
File metadata and controls
35 lines (34 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t, m, n, i, j, c, size;
string s, r;
cin >> t;
while(t--){
cin >> m >> n;
s.clear();
m--; n--;
for(i=0; i<m; i++)
s.push_back('0');
for(i=0; i<n; i++)
s.push_back('1');
size = s.size();
r = s;
reverse(r.begin(), r.end());
for(c=1; r!=s; c++){
for(i=size-1; i>-1; i--){
if(i-1>-1 && s[i-1]<s[i]){
for(j=size-1; j>i && s[i-1]>=s[j]; j--);
swap(s[i-1], s[j]);
sort(s.begin()+i, s.end());
break;
}
}
}
cout << c << endl;
}
return 0;
}