背包变形。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 ;
}

HDU 5800 To My Girlfriend的更多相关文章

  1. hdu 5800 To My Girlfriend + dp

    传送门:hdu 5800 To My Girlfriend 题意:给定n个物品,其中i,j必选,l,m必不选,问组成体积为s的方法一共有多少种 思路:定义dp[i][j][s1][s2],表示前i种物 ...

  2. HDU 5800 To My Girlfriend 背包

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5800 To My Girlfriend Time Limit: 2000/2000 MS (Java ...

  3. HDU 5800 To My Girlfriend(单调DP)

    [题目链接]http://acm.hdu.edu.cn/showproblem.php?pid=5800 [题目大意] 给出一个容量上限s,f[i][j][k][l][m]表示k和l两个物品不能选,i ...

  4. hdu 5800 To My Girlfriend(背包变形)

    To My Girlfriend Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  5. HDU 5800 (DP)

    Problem To My Girlfriend (HDU 5800) 题目大意 给定一个由n个元素组成的序列,和s (n<=1000,s<=1000) 求 :   f (i,j,k,l, ...

  6. hdu5800 To My Girlfriend dp 需要比较扎实的dp基础。

    To My Girlfriend Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  7. HDU5800 To My Girlfriend(DP)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5800 Description Dear Guo I never forget the mom ...

  8. HDU 5584 LCM Walk 数学

    LCM Walk Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5584 ...

  9. HDU 5754 Life Winner Bo (博弈)

    Life Winner Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5754 Description Bo is a "Life W ...

随机推荐

  1. wampserver使用过程中遇到的问题及相关配置

    wampserver集合了Apache+PHP+Mysql 下载地址:点这里 安装过程很方便,一直点下一步就行,中间会提示选择默认的浏览器及文件编辑器 起因: 使用过程中提示: In the http ...

  2. Http压测工具wrk使用指南【转】

    用过了很多压测工具,却一直没找到中意的那款.最近试了wrk感觉不错,写下这份使用指南给自己备忘用,如果能帮到你,那也很好. 安装 wrk支持大多数类UNIX系统,不支持windows.需要操作系统支持 ...

  3. readline与readlines不能同时使用

    fd = open("C:\Users\william\Desktop\dup_file - Copy (2).txt")for i in xrange(0,len(fd.read ...

  4. 快速排序(js版本)

    快速排序的时间复杂度为:O(n*log2n),相比较其他O(n2)的排序算法,还是比较有优势的.原文参考在此处,因为本人对原文的一小段代码有点不理解,所以进行了小的修改. 1.基本思想:在数组的第一个 ...

  5. Android使用Apache的httpmime包post提交数据

    /** * 启动线程向服务器post提交数据 */ public void upLoadPic(final Intent data) { ToastUtils.toastWithMessage(get ...

  6. 基于UDP协议的网络编程

    UDP协议是一种不可靠的网络协议,它在通信实例的两端各建立一个Socket,但这两个Socket之间并没有虚拟链路,这两个Socket只是发送.接收数据报的对象. Java使用DatagramSock ...

  7. Android;设置TextView加粗 代码设置

    我用过paint的那种方式,不好使. private void setTextBold(TextView textView) { //android中为textview动态设置字体为粗体 textVi ...

  8. APK安装时的过滤方式:包名白名单、证书认证

    1.定义一些全局变量,文件位置: Build.java (frameworks\base\core\java\android\os) /** * 包管理方式名称<br> * whiteli ...

  9. PHP中 post 与get的区别 详细说明

    1.Get 方法通过 URL 请求来传递用户的数据,将表单内各字段名称与其内容,以成对的字符串连接,置于 action 属性所指程序的 url 后,如[url]http://www.jincaib.c ...

  10. 分布式版本控制系统Git-----3.图形化Tortoisegit创建本地库并且提交到远程服务器上

    [前提你已经有了自己的远程仓库帐号密码和HTTP地址] PS:图形化会方便,但是个人认为还是敲命令比较好,会锻炼人的思维和逻辑. 1.首先在任意一个地方创建test目录.若要把test目录放在Git的 ...