#include<iostream>
#include<cstdio>
#include<string.h>
#define MAX 10000007
int n;
LL a[MAX];
int main()
{
LL t,m,i,j,sum,xx=1000000007;
scanf("%I64d",&t);
while(t--)
{
scanf("%I64d",&n);
for(j=1; j<=n; j++)
{
scanf("%I64d",&a[j]);
}
a[0] = 0;
for(j=1;j<=n;j++)
{
a[j] = a[j]*j+a[j-1];
a[j] = a[j]%xx;
}
sum = 0;
for(j=1;j<=n;j++)
{
sum = sum+a[j];
sum = sum%xx;
}
printf("%I64d\n",sum);
}
return 0;
#include<cstdio>
#include<string.h>
#define MAX 10000007
#define LL __int64
int n;
LL a[MAX];
int main()
{
LL t,m,i,j,sum,xx=1000000007;
scanf("%I64d",&t);
while(t--)
{
scanf("%I64d",&n);
for(j=1; j<=n; j++)
{
scanf("%I64d",&a[j]);
}
a[0] = 0;
for(j=1;j<=n;j++)
{
a[j] = a[j]*j+a[j-1];
a[j] = a[j]%xx;
}
sum = 0;
for(j=1;j<=n;j++)
{
sum = sum+a[j];
sum = sum%xx;
}
printf("%I64d\n",sum);
}
return 0;
}
很早之前的一道A题,当时挂0.
这道题问你n项之和,DP题,我们根据可以得出
a[i] = a[i]*i + a[i-1];
i代表放第i个数的时候前i个数组成的和等于前i-1的和加上每个等式都会加上a[i],一共有a[i]*i个
举个例子
3
1 2 3
i = 1
a[1] = 1;
i = 2;
a[2] = 1+2*2 = 1 + 2 + (1+2);
i = 3
a[3] = 5+3*3 = 1 + 2 + 3 + (1 + 2) + (2 + 3)+ (1+2+3) = 20
这是个非常好的DP基础题
465

被折叠的 条评论
为什么被折叠?



