题意

n个有体积的物品,问选取一些物品,且不能再继续选有多少方法?

n<=1000

题解

以前的考试题。当时是A了,但发现是数据水,POJ上WA了。

把体积从小到大排序枚举没选的物品中体积最小的。

假设枚举到i,那么1到i-1一定都选。可选的空间为[m-sum[i-1]+1,m]

然后对于后面的数跑DP的到f[i][j]前i个数空间恰好为j时的方案;

贡献为可选空间的方案。

一个优化是倒着枚举i,这样在求f[i][j]时所花费的时间会大大减少。

 #include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int sum[],w[];
int dp[];
int n, m, ans;
int main(){
int cas, i, j, k, ca=;
scanf("%d",&cas);
while(cas--){
scanf("%d%d",&n,&m);
for(i=;i<=n;i++)
scanf("%d",&w[i]);
sort(w+,w++n);
printf("%d ",ca++);
if(w[]>m){printf("0\n");continue;}
sum[]=;
for(i=;i<=n;i++)
sum[i]=sum[i-]+w[i];
ans=;
memset(dp,,sizeof(dp));
dp[]=;
for(i=n;i>=;i--){
for(j=max(,m-sum[i-]-w[i]+);j<=m-sum[i-];j++)
ans+=dp[j];
for(j=m;j>=w[i];j--)
dp[j]+=dp[j-w[i]];
}
printf("%d\n",ans);
}
return ;
}

POJ 3093 Margaritas on the River Walk(背包)的更多相关文章

  1. POJ 3093 Margaritas(Kind of wine) on the River Walk (背包方案统计)

    题目 Description One of the more popular activities in San Antonio is to enjoy margaritas in the park ...

  2. poj[3093]Margaritas On River Walk

    Description One of the more popular activities in San Antonio is to enjoy margaritas in the park alo ...

  3. Margaritas on the River Walk_背包

    Description One of the more popular activities in San Antonio is to enjoy margaritas in the park alo ...

  4. POJ 1636 Prison rearrangement DFS+0/1背包

    题目链接: id=1636">POJ 1636 Prison rearrangement Prison rearrangement Time Limit: 3000MS   Memor ...

  5. POJ 1337 A Lazy Worker(区间DP, 背包变形)

    Description There is a worker who may lack the motivation to perform at his peak level of efficiency ...

  6. POJ Washing Clothes 洗衣服 (01背包,微变型)

    题意:有多种颜色的衣服,由两个人合作来洗,必须洗完一种颜色才能洗下一种,求需要多少时间能洗完. 思路:将衣服按颜色分类,对每种颜色进行01背包,容量上限是该种颜色衣服全部洗完的耗时长一半,其实就是在最 ...

  7. bzoj2287【POJ Challenge】消失之物(退背包)

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 657  Solved: 382[Submit][S ...

  8. [Poj 1015] Jury Compromise 解题报告 (完全背包)

    题目链接:http://poj.org/problem?id=1015 题目: 题解: 我们考虑设计DP状态(因为这很显然是一个完全背包问题不是吗?) dp[j][k]表示在外层循环到i时,选了j个人 ...

  9. POJ 1384 Piggy-Bank (ZOJ 2014 Piggy-Bank) 完全背包

    POJ :http://poj.org/problem?id=1384 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode ...

随机推荐

  1. Java语言特点与学习

    Java语言是一款面向对象的一款高级语言是由Sun Microsystems公司(现已被oracle公司收购).由James Gosling和同事们共同研发,并在1995年正式推出,据oracle官方 ...

  2. BZOJ 3527: [Zjoi2014]力 FFT_卷积

    Code: #include <cmath> #include <cctype> #include <cstdio> #include <cstring> ...

  3. jmeter+ant+jenkins持续集成

    邮件.报告插件和jenkins的war包下载地址:链接:https://pan.baidu.com/s/1gZJ53x50bxVyEsQFjdCkog 密码:1jtz 1.下载ant  网盘地址:链接 ...

  4. hp soap扩展最全说明,附天气预报调用的例子

    自从php5开始,我们可以不用通过php nusoap来创建php soap web service 和调用 soap了,php5内置了 soap扩展.只需要在php.ini中开启soap的exten ...

  5. BZOJ 2119 股市的预测 (后缀数组+RMQ)

    题目大意:求一个字符串中形如$ABA$的串的数量,其中$B$的长度是给定的 有点像[NOI2016]优秀的拆分这道题 先对序列打差分,然后离散,再正反跑$SA$,跑出$st$表 进入正题 $ABA$串 ...

  6. noip复习之拓扑排序

    之前很多很多紫书上的东西我都忘了…… 抄题解的后果…… 做了一下裸题 https://vjudge.net/problem/UVA-10305 拓扑排序还可以来判环 #include<bits/ ...

  7. Vue生命周期函数的应用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. CodeForces 362E Petya and Pipes

    Petya and Pipes Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForces. ...

  9. 带输出參数的存储过程的定义,以及在aso.net中调用

    ALTER proc [dbo].[mp_w_RechargePortalPayPal_All] ( @PayPalOrderNo nvarchar(50), --订单号 @nAccountIDFro ...

  10. UVALive 4225 / HDU 2964 Prime Bases 贪心

    Prime Bases Problem Description Given any integer base b >= 2, it is well known that every positi ...