HS(Handsome)的Ocean在纸上写下O序列。

Ocean认为一个序列的价值的是:序列中不同元素个数。

现在他想知道O序列中所有子序列的价值之和。


比如说:序列7

输入

第一行输入一个整数1<=T<=10000,1<=N<=50,1<=ai<=10。

输出

对每组测试数据,输出一个结果代表所有子序列价值之和。由于结果会很大,请用longlong(%lld)。

样例输入

4
3
1 1 1
4
1 1 1 1
4
10 10 10 8
20
1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10

样例输出

7
15
22
7864320
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn=50+10;

ll c[20];

int a[maxn],b[20];

int main()
{
    int T,n;
    scanf("%d",&T);
    while(T--)
    {
        ll ans=0,t=0,s=0;
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        scanf("%d",&n);
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            b[a[i]]++;//b数组表示某个数出现的次数
        }
        for(int i=1; i<=10; i++)
        {
            if(b[i]!=0)s++;//s表示一共有几个不同的数
        }
        for(int i=1; i<=10; i++)
        {
            if(b[i])
            {
                ll t=pow(2,b[i])-1;
                for(int j=s; j>=1; j--)
                {
                    if(j==1) c[j]+=t;
                    else
                    {
                        c[j]+=c[j-1]*t;
                    }
                }
            }
        }
        for(int i=1; i<=s; i++)
        {
            ans+=i*c[i];
        }
        printf("%lld\n",ans);
    }
    return 0;
}















相关文章:

  • 2021-12-14
  • 2021-11-11
  • 2021-06-04
  • 2021-12-30
  • 2021-11-20
  • 2021-09-10
  • 2022-12-23
猜你喜欢
  • 2021-07-23
  • 2021-07-01
  • 2021-07-06
  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
  • 2022-12-23
相关资源
相似解决方案