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 ...
随机推荐
- AppDelegate 里一个基本的跳转方法,用来在rootView崩溃的时候直接调试我自己的页面
将 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)lau ...
- JVM内存模型,垃圾回收算法
JVM内存模型总体架构图 程序计数器多线程时,当线程数超过CPU数量或CPU内核数量,线程之间就要根据时间片轮询抢夺CPU时间资源.因此每个线程有要有一个独立的程序计数器,记录下一条要运行的指令.线程 ...
- GBDT详解
GBDT(Gradient Boosting Decision Tree) 又叫 MART(Multiple Additive Regression Tree),是一种迭代的决策树算法,该算法由多棵决 ...
- vb.net_介绍
手打 vb.net 是 visual basic.net的简称.提到vb.net,就不能不先提一下vb(Visual Basic) Visaul Basic是windows环境学的一个简单.易学的编程 ...
- PAT 团体程序设计天梯赛-练习集 L1-005. 考试座位号
每个PAT考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位.正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考试座 ...
- Node.js:url
在node运行环境中输入url: > url url { parse: [Function: urlParse], resolve: [Function: urlResolve], resolv ...
- mac 电脑配置cordova
最近发现这个cordova有很多公司在用.所以想试试搭建一个ios平台上的cordova demo.在搭建之前我先说一些跟cordova相关的一些条件. 目前cordova项目在apache上开源.网 ...
- jQuery 截取double数据 重新赋值
$('.prioritySort').each(function(i){ $(this).text($(this).text().substring(0,$(this).text().indexOf( ...
- openwrt下关于snmpd的一些信息
cd /tmp/ 上传: tftp -gr libnetsnmp_5.4.4-1_ar71xx.ipk 192.168.11.56 安装: opkg install libnetsnmp_5.4.4- ...
- FBO
#include <GL/glew.h> #include <GL/freeglut.h> #include <iostream> #pragma comment( ...