2016暑假多校联合---To My Girlfriend

Problem Description
Dear Guo

I never forget the moment I met with you.You carefully asked me: "I have a very difficult problem. Can you teach me?".I replied with a smile, "of course"."I have n items, their weight was a[i]",you said,"Let's define f(i,j,k,l,m) to be the number of the subset of the weight of n items was m in total and has No.i and No.j items without No.k and No.l items.""And then," I asked.You said:"I want to know

∑i=1n∑j=1n∑k=1n∑l=1n∑m=1sf(i,j,k,l,m)(i,j,k,laredifferent)

Sincerely yours,
Liao

 
Input
The first line of input contains an integer T(T≤15) indicating the number of test cases.
Each case contains 2 integers n, s (4≤n≤1000,1≤s≤1000). The next line contains n numbers: a1,a2,…,an (1≤ai≤1000).
 
Output
Each case print the only number — the number of her would modulo 109+7 (both Liao and Guo like the number).

 
Sample Input
2
4 4
1 2 3 4
4 4
1 2 3 4
 
Sample Output
8
8
 
思路:令dp[i][j][s1][s2]表示前i个物品填了j的体积,有s1个物品选为为必选,s2个物品选为必不选的方案数(0<=s1,s2<=2),则有转移方程dp[i][j][s1][s2] = dp[i - 1][j][s1][s2] + dp[i - 1][j - a[i]][s1 - 1][s2] +dp[i - 1][j - a[i]][s1][s2] + dp[i - 1][j][s1][s2 - 1],边界条件为dp[0][0][0][0] = 1,时间复杂度O(NS*3^2);
 
代码如下:
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn = ;
const int mod = 1e9+;
int a[maxn];
int dp[maxn][maxn][][];
int n,s; int main()
{
int T;
scanf("%d",&T);
while(T--)
{
memset(dp,,sizeof(dp));
scanf("%d%d",&n,&s);
for(int i = ;i<=n;i++)
scanf("%d",&a[i]);
dp[][][][]=;
for(int i = ;i<=n;i++)
for(int j = ;j<=s;j++)
for(int s1 = ;s1<=;s1++)
for(int s2 = ;s2<=;s2++)
{
dp[i][j][s1][s2]=(dp[i][j][s1][s2]+dp[i-][j][s1][s2])%mod;
if(j>=a[i])
dp[i][j][s1][s2]=(dp[i][j][s1][s2]+dp[i-][j-a[i]][s1][s2])%mod;
if(s1>&&j>=a[i])
dp[i][j][s1][s2]=(dp[i][j][s1][s2]+dp[i-][j-a[i]][s1-][s2])%mod;
if(s2>)
dp[i][j][s1][s2]=(dp[i][j][s1][s2]+dp[i-][j][s1][s2-])%mod;
}
LL ans = ;
for(int i = ;i<=s;i++)
ans = (ans+dp[n][i][][])%mod;
printf("%lld\n",ans*%mod);
}
}
 

2016暑假多校联合---To My Girlfriend的更多相关文章

  1. 2016暑假多校联合---Rikka with Sequence (线段树)

    2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...

  2. 2016暑假多校联合---Windows 10

    2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...

  3. 2016暑假多校联合---Substring(后缀数组)

    2016暑假多校联合---Substring Problem Description ?? is practicing his program skill, and now he is given a ...

  4. 2016暑假多校联合---A Simple Chess

    2016暑假多校联合---A Simple Chess   Problem Description There is a n×m board, a chess want to go to the po ...

  5. 2016暑假多校联合---Another Meaning

    2016暑假多校联合---Another Meaning Problem Description As is known to all, in many cases, a word has two m ...

  6. 2016暑假多校联合---Death Sequence(递推、前向星)

    原题链接 Problem Description You may heard of the Joseph Problem, the story comes from a Jewish historia ...

  7. 2016暑假多校联合---Counting Intersections

    原题链接 Problem Description Given some segments which are paralleled to the coordinate axis. You need t ...

  8. 2016暑假多校联合---Joint Stacks (STL)

    HDU  5818 Problem Description A stack is a data structure in which all insertions and deletions of e ...

  9. 2016暑假多校联合---GCD

    Problem Description Give you a sequence of N(N≤100,000) integers : a1,...,an(0<ai≤1000,000,000). ...

随机推荐

  1. JS设置cookie、读取cookie、删除cookie

    JS设置cookie.读取cookie.删除cookie       JS设置cookie,注意一定要path=/ ,根目录,不然其他目录可能查询不到..默认是本目录. document.cookie ...

  2. 每天一个linux命令(8):cp 命令

    cp命令用来复制文件或者目录,是Linux系统中最常用的命令之一.一般情况下,shell会设置一个别名,在命令行下复制文件时,如果目标文件已经存在,就会询问是否覆盖,不管你是否使用-i参数.但是如果是 ...

  3. ServletConfig接口默认是哪里实现的?

    问题:Servlet接口默认是哪里实现的? 答:GenericServlet 1.结构 2.ServletConfig.GenericServlet.HttpServlet的关系如下: public ...

  4. silverlight中 Storyboard(动画)的使用,实现球的上下循环移动,左右移动,及旋转功能

    话说,总结应该是个收获的心情,可现在的自己似乎没感觉到哪个喜悦的心情,说明自己做得还不够好,现在还是把一些做好的东西总结下.“总结”是学习,工作中必须的,不能偷这个懒 o(╯□╰)o 实现上下循环移动 ...

  5. Topology and Geometry in OpenCascade-Edge

    Topology and Geometry in OpenCascade-Edge eryar@163.com 摘要Abstract:本文简要介绍了几何造型中的边界表示法(BRep),并结合程序说明O ...

  6. 编译原理LL1文法分析表算法实现

    import hjzgg.first.First; import hjzgg.follow.Follow; import hjzgg.tablenode.TableNode; import hjzgg ...

  7. CSDN 论坛招聘区是不是有潜规则?在Cnblog招个人试试...

    CSDN 论坛招聘区是不是有潜规则? 在招聘区发了两个招聘贴都被删掉了... 而且没有任何提示和原因,或者站内短信提示.... 虽然csdn现在很水...不过在那边之前待了几年还是有点感情的 想顺便内 ...

  8. Android基于mAppWidget实现手绘地图(八)–获取用户地理位置

    你有两种方式确定用户的当前位置: 1.使用安卓标准方式 2. 使用MapWidget的监听器 标准方式: 在你的acivity中加入: LocationManager locManager = (Lo ...

  9. Azure China (11) 使用Azure China Storage Public Blob

    <Windows Azure Platform 系列文章目录> 本文介绍的是国内由世纪互联运维的Azure China 注意:本文介绍的是Azure China Storage Publi ...

  10. 帮助你提高排版技巧的18个 PS 文字特效教程

    Photoshop 文字特效教程对于学习基础的和高级的排版思维有很大的帮助.在这篇文章中,你会发现一组最新发布的文字效果教程.这些高品质的 Photoshop 教程可以帮助你设计出惊人的2D,3D,木 ...