题意:有2辆车运货,每次同时出发,n(<10),各自装货容量c1 c2,问最少运几次运完。

思路:n比较小,打表打出所有能运的组合方式,用背包求出是否能一次运走。然后状压DP运的顺序。

代码:

#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include <iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1024 + 10;
const int M = maxn * 30;
const ull seed = 131;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int c1, c2, n;
int w[maxn];
int dp[1 << 12];
int can[maxn];
int bag[maxn], v[maxn];
int main(){
int T, ca = 1;
scanf("%d", &T);
while(T--){
scanf("%d%d%d", &n, &c1, &c2);
for(int i = 0; i < n; i++) scanf("%d", &w[i]); int cnt = 0;
int tot = 0, sum = 0;
for(int i = 1; i < (1 << n); i++){
tot = sum = 0;
for(int j = 0; j < n; j++){
if(i & (1 << j)) v[++tot] = w[j], sum += w[j];
}
memset(bag, 0, sizeof(bag));
for(int j = 1; j <= tot; j++){
for(int k = c1; k >= v[j]; k--){
bag[k] = max(bag[k], bag[k - v[j]] + v[j]);
}
}
if(c2 >= sum - bag[c1]) can[cnt++] = i;
} memset(dp, INF, sizeof(dp));
dp[0] = 0;
for(int i = 0; i < (1 << n); i++){
if(dp[i] == INF) continue;
for(int j = 0; j < cnt; j++){
if((i & can[j]) == 0){
dp[i | can[j]] = min(dp[i | can[j]], dp[i] + 1); }
}
} printf("Scenario #%d:\n%d\n\n", ca++, dp[(1 << n) - 1]);
}
return 0;
}

POJ 2923 Relocation(状压DP)题解的更多相关文章

  1. POJ 3254 简单状压DP

    没什么可说的,入门级状压DP.直接撸掉 #include <iostream> #include <cstring> #include <cstdlib> #inc ...

  2. POJ 3254 & POJ 1185(状压DP入门)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16773   Accepted: 8860 Desc ...

  3. Corn Fields POJ - 3254 (状压dp)

    题目链接: Corn Fields  POJ - 3254 题目大意:给你一个n*m的矩阵,矩阵的元素只包括0和1,0代表当前的位置不能放置人,1代表当前的位置可以放人,当你决定放人的时候,这个人的四 ...

  4. poj 1185 (状压dp)

    Problem 炮兵阵地 题目大意 给你一张n*m的地图,一些地区是空地,一些地区是障碍. 可以在空地上布置炮兵部队,炮兵部队的攻击范围为上下左右各两格. 询问最多可以布置多少个炮兵部队,且互不伤害. ...

  5. POJ 1185 经典状压dp

    做了很久的题 有注释 #include<stdio.h> #include<string.h> #include<algorithm> #include<ma ...

  6. POJ 3254 - Corn Fields - [状压DP水题]

    题目链接:http://poj.org/problem?id=3254 Time Limit: 2000MS Memory Limit: 65536K Description Farmer John ...

  7. Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP

    Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10061 ...

  8. 【POJ 2923】Relocation(状压DP+DP)

    题意是给你n个物品,每次两辆车运,容量分别是c1,c2,求最少运送次数.好像不是很好想,我看了网上的题解才做出来.先用状压DP计算i状态下,第一辆可以运送的重量,用该状态的重量总和-第一辆可以运送的, ...

  9. HDU 2923 Relocation(状压dp+01背包)

    题目代号:HDU2923 题目链接:http://poj.org/problem?id=2923 Relocation Time Limit: 1000MS Memory Limit: 65536K ...

随机推荐

  1. 单台服务器-利用docker搭建Redis哨兵集群模式

    前言:只有一台华为云服务器,所以打算创建三个容器来模拟三个服务器了. 一:拉取redis镜像 二:拉取redis.conf文件 放在自定义的目录下:wget -c http://download.re ...

  2. JAVA SSM整合流程以及注意点

    1.搭建整合环境 整合说明:SSM整合可以使用多种方式,咱们会选择XML + 注解的方式 先搭建整合的环境 先把Spring的配置搭建完成 再使用Spring整合SpringMVC框架 最后使用Spr ...

  3. Mac 禁用动画

    # opening and closing windows and popovers defaults write -g NSAutomaticWindowAnimationsEnabled -boo ...

  4. 【转】DDD-应用架构

    简介: 应用架构,指软件系统中固定不变的代码结构.设计模式.规范和组件间的通信方式.在应用开发中架构之所以是最重要的第一步,因为一个好的架构能让系统安全.稳定.快速迭代.但是今天我们在做业务研发时,更 ...

  5. 题解 UVA11694 【Gokigen Naname谜题 Gokigen Naname】

    题目 题解 考场上连暴力都不会打的码农题,深搜是真的难 /kk 前置问题 怎么输出"\" cout<<"\\"; 2.怎么处理不在一个环里,可以考虑 ...

  6. 八:SpringBoot-集成JPA持久层框架,简化数据库操作

    SpringBoot-集成JPA持久层框架,简化数据库操作 1.JPA框架简介 1.1 JPA与Hibernate的关系: 2.SpringBoot整合JPA Spring Data JPA概述: S ...

  7. Mybatis(二)实例练习

    文章目录 实例练习Mybatis,实现一个简单的登录功能. 增.删.改:操作返回Int类型. 查询操作返回实体对象. 首先需要导入相关的包. #导包: #建表 在数据库中新建一个用户mybatis,然 ...

  8. Geospark-属性字段处理

    Geospark将从shapefile.csv等格式文件以及DataFrame中的读取的字段保存到了Geometry的userData字段中,可以通过调用.getUserData()方法获取,他会返回 ...

  9. juniper srx系列配置端口映射 转载

    http://www.cnblogs.com/pinpin/p/9895815.html

  10. RabbitMQ (基础知识)

    AMQP简介 AMQP(Advanced Message Queue )即:高级消息队列协议:,是应用层协议的一个开放标准,为面向消息的中间件设计:高级消息队列协议使得遵从该规范的客户端应用和消息中间 ...