Relocation 状态压缩DP
Description
Emma and Eric are moving to their new house they bought after returning from their honeymoon. Fortunately, they have a few friends helping them relocate. To move the furniture, they only have two compact cars, which complicates everything a bit. Since the furniture does not fit into the cars, Eric wants to put them on top of the cars. However, both cars only support a certain weight on their roof, so they will have to do several trips to transport everything. The schedule for the move is planed like this:
- At their old place, they will put furniture on both cars.
- Then, they will drive to their new place with the two cars and carry the furniture upstairs.
- Finally, everybody will return to their old place and the process continues until everything is moved to the new place.
Note, that the group is always staying together so that they can have more fun and nobody feels lonely. Since the distance between the houses is quite large, Eric wants to make as few trips as possible.
Given the weights wi of each individual piece of furniture and the capacities C1 and C2 of the two cars, how many trips to the new house does the party have to make to move all the furniture? If a car has capacity C, the sum of the weights of all the furniture it loads for one trip can be at most C.
Input
The first line contains the number of scenarios. Each scenario consists of one line containing three numbers n, C1 and C2. C1 and C2 are the capacities of the cars (1 ≤ Ci ≤ 100) and n is the number of pieces of furniture (1 ≤ n ≤ 10). The following line will contain n integers w1, …, wn, the weights of the furniture (1 ≤ wi ≤ 100). It is guaranteed that each piece of furniture can be loaded by at least one of the two cars.
Output
The output for every scenario begins with a line containing “Scenario #i:”, where i is the number of the scenario starting at 1. Then print a single line with the number of trips to the new house they have to make to move all the furniture. Terminate each scenario with a blank line.
Sample Input
2
6 12 13
3 9 13 3 10 11
7 1 100
1 2 33 50 50 67 98
Sample Output
Scenario #1:
2 Scenario #2:
3
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <map>
using namespace std;
int c1,c2,vi[],a[],n,dp[];
bool check(int x)
{
int i,j,sum=;
memset(vi,,sizeof(vi));
vi[]=;
for(i=;i<n;i++)
{
if(x&(<<i))
{
sum+=a[i];
for(j=;j>=a[i];j--)
if(vi[j-a[i]])
vi[j]=;
}
}
for(i=c1;i>=;i--)
{
if(vi[i]&&sum-i<=c2)return ;
}
return ;
}
int main()
{
int t,i,j,b[(<<)],bn,sum,cas=;
scanf("%d",&t);
while(t--)
{
sum=;
scanf("%d%d%d",&n,&c1,&c2);
if(c1>c2)swap(c1,c2);
for(i=;i<n;i++)
scanf("%d",&a[i]),sum+=a[i];
bn=;
for(i=;i<(<<n);i++)
{
if(check(i))
b[bn++]=i;
}
for(i=;i<<<n;i++)dp[i]=;
dp[]=;
for(i=;i<bn;i++)
{
for(j=(<<n)-;j>=;j--)
if((b[i]|j)==j)
dp[j]=min(dp[j],dp[b[i]^j]+);
}
cout<<"Scenario #"<<cas++<<":"<<endl;
cout<<dp[(<<n)-]<<endl<<endl;
}
}
Relocation 状态压缩DP的更多相关文章
- hoj2662 状态压缩dp
Pieces Assignment My Tags (Edit) Source : zhouguyue Time limit : 1 sec Memory limit : 64 M S ...
- POJ 3254 Corn Fields(状态压缩DP)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4739 Accepted: 2506 Descr ...
- [知识点]状态压缩DP
// 此博文为迁移而来,写于2015年7月15日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w6jf.html 1.前 ...
- HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP
题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...
- DP大作战—状态压缩dp
题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...
- 状态压缩dp问题
问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...
- BZOJ-1226 学校食堂Dining 状态压缩DP
1226: [SDOI2009]学校食堂Dining Time Limit: 10 Sec Memory Limit: 259 MB Submit: 588 Solved: 360 [Submit][ ...
- Marriage Ceremonies(状态压缩dp)
Marriage Ceremonies Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- HDU 1074 (状态压缩DP)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:有N个作业(N<=15),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ...
随机推荐
- 现在开始学习WPF了,mongodb在整理一下
回忆一下自己学习mongodb的过程 1安装 2增删改查 3数据类型转换 4GridFS 5权限管理--开启权限之前先建立一个超级用户(admin库中),开启权限,用该用户登陆,进入admin数据库( ...
- 利用WHID为隔离主机建立隐秘通道
0 引言 从2014年BADUSB出现以后,USB-HID攻击就这一直被关注,且具争议.争议的焦点是USB-HID的实战效果过于“鸡肋”,无论从早期的BADUSB,还是到后来的各种USB-HID设备, ...
- Ext.form.RadioGroup
var radiogroup = new Ext.form.RadioGroup({ id:'sex', parentColor : true, fieldLabel:'性别', width: 100 ...
- Begin the new life as a coder
今天刚刚开通博客园的博客频道,这里将成为自我成长点滴记录的土壤!从今天开始,从这篇博文开始,我将分享自己从一个fresher开始的成长经历.原与广大仁人志士共同在程序中共享快乐!我真是太高兴了 :D
- Java Integer封装类的IntegerCache内部类
个人理解,不喜勿喷,欢迎指正. 首先看下面这段代码,猜一下输出结果是什么 Integer a = 10; Integer b = 10; System.out.println(a == b); a = ...
- ASP.NET Core 运行原理解剖[5]:Authentication
在现代应用程序中,认证已不再是简单的将用户凭证保存在浏览器中,而要适应多种场景,如App,WebAPI,第三方登录等等.在 ASP.NET 4.x 时代的Windows认证和Forms认证已无法满足现 ...
- 短视频 SDK 功能点技术实现方式详解
第三方短视频解决方案作为快速切入短视频行业的首选方式,选择一款功能齐全.性能优异的短视频解决方案十分重要. 今天我们来谈谈短视频 SDK 6大重要功能点及其技术实现方式. 短视频拍摄 断点续拍 指在拍 ...
- HTML解析原理概括(转载)
HTML解析原理 标准的web前端工程师需要知道 ◎浏览器(或者相应播放器)的渲染/重绘原理 这我得加把劲了.我还真的说的不是很清楚,我就G下,结果不是很多,找到了有一个,就记下来了... 以下部分 ...
- SNS团队Beta阶段第七次站立会议(2017.5.28)
1.立会照片 2.每个人的工作 成员 今天已完成的工作 罗于婕 对界面各部分的图标进行完善.美化 龚晓婷 对于历史记录功能进一步完善 林仕庄 对于历史记录功能进一步完善 刘海兰 协调界面的整体美化 念 ...
- 使用Eclipse Egit与码云管理你的代码
总体流程: 建立远程仓库 建立本地仓库并与远程仓库关联 将Eclipse中的项目提交到本地仓库并进而push到远程仓库 一. 配置Eclipse EGit 图解Eclipse中安装及配置EGit插件中 ...