Skip to content

Instantly share code, notes, and snippets.

@yao2030
Created June 21, 2014 03:22
Show Gist options
  • Save yao2030/a54164dcd98a75779665 to your computer and use it in GitHub Desktop.
Save yao2030/a54164dcd98a75779665 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cmath>
using namespace std;
const int NUMS = 16;
int num[NUMS + 10];
inline int Bit(int n, int i) { return ( n & (1 << i)); }
int main(void) {
int t;
cin >> t;
while(t--) {
int n;
cin >> n;
int totalSolutions = 0;
for (int i = 0; i < n; ++i) {
cin >> num[i];
}
int tmp = pow(2.0, n);
for (int i = 0; i < tmp; i++) {
int sum = 0;
for (int k = 0; k < n; ++k) {
if (Bit(i, k))
sum += num[k];
}
if (sum % 7 == 0)
totalSolutions++;
}
cout << totalSolutions << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment