Array Concatanation Count the number of boolean arrays with a a zeroes and b b ones,…
- User
Array Concatanation Count the number of boolean arrays with a a zeroes and b b ones, such that the following holds.
Let A A be the boolean array and A i A i
subarray subarray( A 1 A 1 , A 2 A 2 .... A i A i ). Concatenate A 1 A 1 , A 2 A 2 ... A a + b A a+b and call this array B B. The number of ones on odd and even indexes in the array B B are equal.
Print the answer modulo 1000000007 1000000007.
Note: a a + b b is always even.
Input Format The first line of input will contain a single integer T T, denoting the number of test cases. Each test case consists of one line of input. The first line and only line of each test case contain two integers a a and b b. Output Format For each test case, output on a new line the answer to the problem.
Constraints 1 ≤ T ≤ 100 1≤T≤100 0 ≤ a ≤ 2 ∗ 1 0 6 0≤a≤2∗10 6
0 ≤ b ≤ 2 ∗ 1 0 6 0≤b≤2∗10 6
a + b
0 a+b>0 a + b a+b is even. The sum of a + b a+b over all test cases won't exceed 2 ⋅ 1 0 6 2⋅10 6 . Sample 1: Input Output 3 2 2 1 5 1005 2005 2 2 74974562 #include <bits/stdc++.h> using namespace std;
int main() { // your code goes here int M=1000000007; int t;cin>>t; vector v; vector vp; while(t--){ int a,b;cin>>a>>b; int sizee=(a%M+b%M)%M; int A[sizee]; for(int i=0;i<sizee;i++){ cin>>A[i]; } for(int i=0;i<a;i++){ for(int j=0;j<b;j++){ if(i==1)break; v.push_back(A[i][j]); } } // add subarray int sum=0; for(int i=0;i<v.size();i++) { vp.push_back(v[i]); } int ones=0; int evens=0; for(int i=0;i<vp.size();i+=2){ if(vp[i]==1){ ones++; } } for(int i=1;i<vp.size();i+=2){ if(vp[i]==0){ evens++; } } } } in c++ correct this code
- Assistant