Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define debug(n) cout<<(n)<<endl;
const ll INF = 2e18 + 99;
ll powd(ll a, ll b){
if(b == 0){
return 1;
}
for(ll i = 1; i < b; i++){
a = a * 2;
}
return a;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
ll n;
cin>>n;
ll x = 0, y = 0, k;
for(ll i = 0; i < n; i++){
cin>>k;
if(k == 1){
x++;
continue;
}
if(k == 0){
y++;
continue;
}
}
cout<<(x * powd(2,y))<<endl;
}
}
Copy The Code &
Try With Live Editor
Input
5
5
1 2 3 4 5
2
1000 1000
2
1 0
5
3 0 2 1 1
5
2 1 0 3 0
5
1 2 3 4 5
2
1000 1000
2
1 0
5
3 0 2 1 1
5
2 1 0 3 0
Output
1
0
2
4
4
0
2
4
4
Demonstration
Codeforcess Solution 1582-B B. Luntik and Subsequences ,C++, Java, Js and Python ,1582-B,Codeforcess Solution