HDU 5800 To My Girlfriend
背包变形。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的更多相关文章
- hdu 5800 To My Girlfriend + dp
传送门:hdu 5800 To My Girlfriend 题意:给定n个物品,其中i,j必选,l,m必不选,问组成体积为s的方法一共有多少种 思路:定义dp[i][j][s1][s2],表示前i种物 ...
- HDU 5800 To My Girlfriend 背包
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5800 To My Girlfriend Time Limit: 2000/2000 MS (Java ...
- 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 ...
- hdu 5800 To My Girlfriend(背包变形)
To My Girlfriend Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 5800 (DP)
Problem To My Girlfriend (HDU 5800) 题目大意 给定一个由n个元素组成的序列,和s (n<=1000,s<=1000) 求 : f (i,j,k,l, ...
- hdu5800 To My Girlfriend dp 需要比较扎实的dp基础。
To My Girlfriend Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU5800 To My Girlfriend(DP)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5800 Description Dear Guo I never forget the mom ...
- HDU 5584 LCM Walk 数学
LCM Walk Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5584 ...
- HDU 5754 Life Winner Bo (博弈)
Life Winner Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5754 Description Bo is a "Life W ...
随机推荐
- Remote小Demo
Demo基于http://www.cnblogs.com/zhili/p/NETRemoting.html RemotingObj using System; using System.Collect ...
- 我喜欢的两个js类实现方式
闭包实现 变量是不会变的:) var myApplication = function(){ var name = 'Yuri'; var age = '34'; var status = 'sing ...
- PHP 分析1
D:\wamp64\www\practice test 3: PHP 显示乱码 http://localhost/practice/ex1_5_stu.php <html><meta ...
- Linux镜像资源收集
1.企业 搜狐开源镜像站: http://mirrors.sohu.com/ 网易开源镜像站: http://mirrors.163.com/ 阿里开源镜像站: http://mirrors.aliy ...
- datatables.js 里面遇到的问题
1. 假如需要A行的data 和 B行的data 合并 在B行 data:name 在A行的 render:function(){ return data+full.name 此时返回的就是A+B ...
- jsvc 以daemon方式运行tomcat
原理: 使用jsvc来运行服务,没有了默认8005的shutdown端口: 主进程pid为1,fork 2个进程 运行方式参考:http://commons.apache.org/proper/com ...
- iOS开发中怎么样使用激光推送
1.注册激光推送的账号 ----> 创建应用 2.上传推送测试和发布的p12文件 注意密码的填写 3.下载sdk并拖进工程里 4.在build setting 搜索search 把路径改一 ...
- 《JS权威指南学习总结--6.6属性getter和setter》
内容要点: 一.对象属性 对象属性是由名字.值和一组特性构成的.在ES5中,属性值可以用一个或两个方法替代,这两个方法就是getter和setter.由getter和setter定义的属性称做 ...
- 编写高质量iOS代码的52个有效方法1-1
一.使用向前声明(@class)的好处 1.有效减少编译器编译的时间: 2.有效避免循环引用: 二.字面量语法的好处 1.字面常量 精简.可用于所有数据类型,如: NSNumber *intNumbe ...
- java 读取excel 将数据插入到数据库
import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.sql.Con ...