Since the problem set was hard, here is an easy task for you to solve.
You are given an array a consisting of n integers, and your task is to calculate the summation of the multiplication of all subsets of array a. (See the note for more clarifications)
A subset of an array a is defined as a set of elements that can be obtained by deleting zero or more elements from the original array a.
The first line contains an integer T, where T is the number of test cases.
The first line of each test case contains an integer n (1 ≤ n ≤ 105), where n is the size of array a.
The second line of each test case contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106), giving the array a.
For each test case, print a single line containing the summation of the multiplication of all subsets of array a. Since this number may be too large, print the answer modulo 109 + 7.
3 3 1 2 3 2 3 5 1 4512
23 23 4512
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
In the first test case, the array a has 6 subsets, and the answer is calculated as follow:
题意:
按规定子集乘积的和。
算法:
动态规划
看了时限反应过来
代码:
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
typedef long long ll;
int t;
int n;
int a[100005];
ll dp[100005];
const ll b=pow(10,9)+7;
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
dp[0]=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
dp[i]=(dp[i-1]+a[i]+a[i]*dp[i-1])%b;
}
printf("%d\n",dp[n]);
}
return 0;
}