Backpack deformation. Dp[i][j][g][h] represents the first I number, and for J, there is a G required, there is an H must not select the number of schemes.
The answer is sum{dp[n][j][2][2]}*4.
#pragmaComment (linker, "/stack:1024000000,1024000000")#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<map>#include<Set>#include<queue>#include<stack>#include<iostream>using namespaceStd;typedefLong LongLL;Const DoublePi=acos (-1.0), eps=1e-8;voidFile () {freopen ("D:\\in.txt","R", stdin); Freopen ("D:\\out.txt","W", stdout);} InlineintRead () {Charc = GetChar (); while(!isdigit (c)) C =GetChar (); intx =0; while(IsDigit (c)) {x = x *Ten+ C-'0'; c =GetChar ();} returnx;}Const intmaxn= ++Ten;intdp[maxn][maxn][3][3],f[maxn][maxn][3][3];intmod=1e9+7;intT,N,S,A[MAXN];intMain () {scanf ("%d", &t); while(t--) {scanf ("%d%d",&n,&s); for(intI=1; i<=n;i++) scanf ("%d",&A[i]); Memset (DP,0,sizeofDP); dp[0][0][0][0]=1; for(intI=1; i<=n;i++) { for(intj=0; j<=s;j++) { for(intp=0;p <=2;p + +) { for(intH=0; h<=2; h++) { intnum=0; Num= (num+dp[i-1][J][P][H])%MoD; if(j-a[i]>=0) num= (num+dp[i-1][J-A[I]][P][H])%MoD; if(P-1>=0&&j>=a[i]) num= (num+dp[i-1][j-a[i]][p-1][H])%MoD; if(h1>=0) num= (num+dp[i-1][j][p][h-1])%MoD; DP[I][J][P][H]=num; } }}} LL ans=0; for(intI=1; i<=s;i++) ans= (ans+dp[n][i][2][2])%MoD; printf ("%lld\n", (ans*4)%(LL) mod); } return 0;}
HDU 5800 to My girlfriend