Shashank is very excited after learning about the linked list. He learned about how to merge two linked lists. When we merge two linked lists, the order of the elements of each list doesn't change. For example, if we merge and , is a valid merge, while is not a valid merge because is appears before.
Shashank wants you to solve a problem for him: You are given two lists having sizes and . How many ways can we merge both the lists? It is given that all elements are distinct. As your answer can be quite large, Shashank wants you to print it .
Input Format
The first line contains an integer , the number of test cases.
Each of the next lines contains two integers and .
The first line contains an integer , the number of test cases.
Each of the next lines contains two integers and .
Output Format
Print the value of the answer .
Print the value of the answer .
Constraints
Sample Input
1
2 2
Sample Output
6
Explanation
Suppose the two lists are and . The different ways of merging these lists are given below:
Solution:
- #include <bits/stdc++.h>
- #define pb push_back
- using namespace std;
- typedef long long LL;
- const int S = 100003;
- const int MOD = 1e9+7;
- const double pi = 2 * acos (0.0);
- int _Int(){int x; scanf("%d", &x); return x;}
- LL _LLi(){LL x; scanf("%lld", &x); return x;}
- void pruts(){puts("-1");exit(EXIT_SUCCESS);}
- int dirX[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
- int dirY[] = { 0, 1, 0, -1, 1, -1, -1, 1 };
- int rX[] = { 1, 1, 2, 2, -1, -1, -2, -2 };
- int rY[] = { 2, -2, 1, -1, 2, -2, 1, -1 };
- template < class T > T tri_Area( T x1, T y1, T x2, T y2, T x3, T y3 ){ return abs( x1*( y2-y3 ) - y1*( x2-x3 ) + ( x2*y3-x3*y2 ) );};
- template < class T > T Distance( T x1, T y1, T x2, T y2 ){ return sqrt( ( x1-x2 ) * ( x1-x2 ) + ( y1-y2 ) * ( y1-y2 ) ); };
- template < class T > T bigMod( T n, T p, T m ){ if( p == 0 )return 1; if( p&1 )return ( n*bigMod( n, p-1, m ) )%m; T x = bigMod( n, p/2, m ); return ( x*x )%m; };
- int sset(int N, int pos){return N=N|(1<<pos);}
- bool check(int N, int pos){return (bool)(N&(1<<pos));}
- int reset(int N, int pos){return N=N&~(1<<pos);}
- /*******************###########################################********************
- ********************## MD. YA-SEEN ARAFAT(ThunderStroke) ##********************
- ********************## CSE, University of Asia Pacific ##********************
- ********************###########################################********************/
- string s, Ans[ (1<<16)+2 ];
- void Love(){
- int t = _Int();
- while( t-- ){
- int n = _Int();
- cin >> s;
- int k = 0;
- for( int i = 1; i < ( 1 << n ); i++ ){
- int ind = 0;
- int v = i;
- string temp;
- while( v ){
- if( v&1 )temp.pb(s[ind]);
- ind++;
- v >>= 1;
- }
- if( temp.size() )Ans[k++] = temp;
- temp.clear();
- }
- sort(Ans, Ans+k);
- for( int i = 0; i < k; i++ )cout << Ans[i] << endl;
- for( int i = 0; i < k; i++ )Ans[i].clear();
- }
- }
- int main(){
- #ifndef ONLINE_JUDGE
- // freopen("in.txt", "r", stdin);
- // freopen("n.txt", "w", stdout);
- #endif
- Love();
- return 0;
- }
No comments:
Post a Comment