题目中提到 It guarantees that the sum of T[i] in each test case is no more than 2000 and 1 <= T[i].
加上一堆顺序,基本可以猜到是属于递推形的dp
dp[i][j]表示前i个和为j时的方案数
dp方程: dp[i][j]+=dp[i][j-k]
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
const int INF=0x3f3f3f3f;
const double eps=1e-;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
const int MAXN=;
int n,m,tt;
int a[MAXN];
int dp[MAXN][MAXN];
int main()
{
int i,j,k,ca=;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
scanf("%d",&tt);
while(tt--)
{
scanf("%d",&n);
int sum=;
for(i=;i<n;i++)
{
scanf("%d",a+i);
sum+=a[i];
}
cl(dp);
for(i=;i<=a[];i++)
{
dp[][i]=;
}
for(i=;i<n;i++)
{
for(j=;j<=sum/;j++)
{
for(k=;k<=a[i];k++)
{
if(j-k<) break;
dp[i][j]+=dp[i-][j-k];
dp[i][j]%=MOD;
}
}
}
printf("%d\n",dp[n-][sum/]);
}
}