#include<stdio.h>
#include<iostream>
#define MAX 13
long long int arr[MAX], length;
long long int bfs(void)
{
long long int jrr[21][MAX], temp;
memset(jrr, 0, sizeof(jrr));
jrr[arr[0]][0] = 1;
for (int i = 0; i < length - 2; i++)
{
for (int j = 0; j <= 20; j++)
{
if (jrr[j][i] != 0)
{
temp = j + arr[i + 1];
if (temp >= 0 && temp <= 20)
jrr[temp][i + 1] = (jrr[j][i] + jrr[temp][i + 1]) % 1234567891;
temp = j - arr[i + 1];
if (temp >= 0 && temp <= 20)
jrr[temp][i + 1] = (jrr[j][i] + jrr[temp][i + 1]) % 1234567891;
}
}
}
return jrr[arr[length - 1]][length - 2];
}
int main(void)
{
freopen("input.txt", "r", stdin);
int num;
scanf("%d", &num);
for (int tc = 1; tc <= num; tc++)
{
scanf("%lld", &length);
for (int i = 0; i < length; i++)
scanf("%lld", &arr[i]);
printf("#%d %lld\n", tc, bfs());
}
}
댓글