标签:
#include<bits/stdc++.h> using namespace std; #define LL long long const int maxn = 1005; const int mod = 1e9+7; int a[maxn]; int dp[maxn][maxn][3][3]; int n,s; int main() { int T; scanf("%d",&T); while(T--) { memset(dp,0,sizeof(dp)); scanf("%d%d",&n,&s); for(int i = 1;i<=n;i++) scanf("%d",&a[i]); dp[0][0][0][0]=1; for(int i = 1;i<=n;i++) for(int j = 0;j<=s;j++) for(int s1 = 0;s1<=2;s1++) for(int s2 = 0;s2<=2;s2++) { dp[i][j][s1][s2]=(dp[i][j][s1][s2]+dp[i-1][j][s1][s2])%mod; if(j>=a[i]) dp[i][j][s1][s2]=(dp[i][j][s1][s2]+dp[i-1][j-a[i]][s1][s2])%mod; if(s1>0&&j>=a[i]) dp[i][j][s1][s2]=(dp[i][j][s1][s2]+dp[i-1][j-a[i]][s1-1][s2])%mod; if(s2>0) dp[i][j][s1][s2]=(dp[i][j][s1][s2]+dp[i-1][j][s1][s2-1])%mod; } LL ans = 0; for(int i = 1;i<=s;i++) ans = (ans+dp[n][i][2][2])%mod; printf("%lld\n",ans*4%mod); } }
标签:
原文地址:http://www.cnblogs.com/chen9510/p/5740869.html