背包变形。dp[i][j][g][h]表示前i个数字,和为j,有g个必选,有h个必不选的方案数。

答案为sum{dp[n][j][2][2]}*4

#pragma comment(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 namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
inline int read()
{
char c = getchar(); while(!isdigit(c)) c = getchar();
int x = ;
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
return x;
} const int maxn=+;
int dp[maxn][maxn][][],f[maxn][maxn][][];
int mod=1e9+;
int T,n,s,a[maxn]; int main()
{
scanf("%d",&T); while(T--)
{
scanf("%d%d",&n,&s);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
memset(dp,,sizeof dp); dp[][][][]=; for(int i=;i<=n;i++)
{
for(int j=;j<=s;j++)
{
for(int p=;p<=;p++)
{
for(int h=;h<=;h++)
{
int num=;
num=(num+dp[i-][j][p][h])%mod;
if(j-a[i]>=) num=(num+dp[i-][j-a[i]][p][h])%mod;
if(p->=&&j>=a[i]) num=(num+dp[i-][j-a[i]][p-][h])%mod;
if(h->=) num=(num+dp[i-][j][p][h-])%mod;
dp[i][j][p][h]=num;
}
}
}
}
LL ans=;
for(int i=;i<=s;i++) ans=(ans+dp[n][i][][])%mod;
printf("%lld\n",(ans*)%(LL)mod);
}
return ;
}

最新文章

  1. yii2 利用小部件生成后台左边菜单栏
  2. Rabin-Miller算法
  3. Windows命令行下pip安装python whl包
  4. Object Storage(Swift)安装过程——Havana
  5. jQuery下的显示和隐藏
  6. Visifire Chart控件设置 柱状图 条的宽窄
  7. sortable items不让他拖,也不让他放。cancel不然他拖动
  8. 使用kafka connect,将数据批量写到hdfs完整过程
  9. ThinkPHP3.2 --- 中文乱码问题
  10. Openvswitch手册(1): 架构,SSL, Manager, Bridge
  11. 使用MXNet的NDArray来处理数据
  12. 数组长度为len,数组元素的范围是0到len-1,找出数组的重复元素
  13. iptables防火墙端口操作
  14. provisional headers are shown 知多少
  15. @ImportResource 导入Spring 的xml配置文件
  16. 获取请求地址的IP地址
  17. app后端设计-- 数据库分表
  18. 如何打开chrome中flash debug player
  19. 确定有限自动机 valid number
  20. Jump Game - LeetCode

热门文章

  1. 【linux-shell】rsync
  2. python 学习 有序字典
  3. SSH整合例子
  4. 【MySQL】使用 Optimizer Trace 观察SQL执行过程
  5. RTL-SDR基础环境安装
  6. iOS开发播放文本
  7. 7 个 jQuery 最佳实践
  8. 朱丽叶—Cuda+OSG
  9. SHELL自动运行脚本
  10. MVC3+EF4.1学习系列(四)----- ORM关系的处理