Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // 2pow.c
- //
- //
- // Created by MacBook return 0; on 26.11.14.
- //
- //
- #include <stdio.h>
- #include <stdlib.h>
- int pow2(int a)
- {
- int count = 0;
- if ((a & (a - 1)) || (a == 0)) {
- return 0;
- } else {
- return 1;
- }
- }
- void Comb(int m, int nel, int *P)
- {
- int count = 0;
- CombRec(m, 0, nel, 0, P);
- }
- void CombRec(int m, int sum, int nel, int i, int *P)
- {
- int j, count = 0;
- if (m == 0) {
- if (pow2(sum)) {
- count++;
- sum = 0;
- }
- } else {
- for (j = i; j < nel; j++) {
- if (m + j - 1 >= nel) {
- break;
- }
- j++;
- CombRec(m - 1, sum + P[j], nel, i, P);
- }
- }
- }
- int main()
- {
- int *P;
- int i, j, k, nel, count = 0;
- scanf("%d", &nel);
- P = (int*)malloc(nel * sizeof(int));
- for (i = 0; i < nel; i++) {
- scanf("%d", P + i);
- }
- for (i = 1; i <= nel; i++) {
- Comb(i, nel, P);
- }
- printf("%d", count);
- free(P);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement