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),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ... 
随机推荐
- macaca测试web小例子
			上午刚把macaca的环境在公司的电脑上吧web 端的环境给搭建好,于是乎,看看网上的例子,看看官方的文档 https://macacajs.github.io/wd.py/ 可以在这个链接看到原滋原 ... 
- OCUpload的简单介绍与使用
			OCUpload (One Click Upload)译成中文就是一键上传的意思.它是JQuery的一个插件. 对于传统的文件上传,只能通过form表单,将enctype设置为multipart ... 
- 性能测试中vmstat命令的常见使用。
			vmstat是Linux中常用的一个命令,尤其是在进行性能测试时,使用该命令,往往能辅助我们进行性能问题定位. 我们先看一下这个命令执行得到的数据. [root@xxx ~]# vmstat 1 10 ... 
- 没有闲话和grunt.initConfig()
			grunt.initConfig()为Gruntfile.js的核心部分,它接收对象作为参数. 对象包含两种类型的属性,一种是单纯的变量,一种是task类型.举个栗子: grunt.initConfi ... 
- [2017BUAA软工助教]评论汇总
			一 邹欣 周筠 飞龙 二 学校 课程 教师 助教1 助教2 助教3 福州 软件工程1715K 柯逍 谢涛 软件工程1715Z 张栋 刘乾 汪培侨 软件工程1715W 汪璟玢 曾逸群 卞倩虹 李娟 集美 ... 
- 201521123038 《Java程序设计》 第五周学习总结
			201521123038 <Java程序设计> 第五周学习总结 1. 本周学习总结 2. 书面作业 1.代码阅读:Child压缩包内源代码 1.1 com.parent包中Child.ja ... 
- 201521145048《Java程序设计管理》第一周学习总结
			1. 本周学习总结 学习并了解Java的发展与历史 在网上视频中学习Java 了解并区分JVM JRE JDK 将java与已学语言做比较,发现相同处 2. 书面作业 Q1.为什么java程序可以跨平 ... 
- JAVA课程设计---学生基本信息管理系统(201521123039 王兴)
			1.团队课程设计博客链接 http://www.cnblogs.com/zyjjj/p/7061880.html 2.个人负责模块或任务说明 函数 功能说明 Search 查找学生信息,分为两种查找方 ... 
- 201521123039《java程序设计》第十四周学习总结
			1. 本周学习总结 2. 书面作业 1. MySQL数据库基本操作 建立数据库,将自己的姓名.学号作为一条记录插入.(截图,需出现自己的学号.姓名) 在自己建立的数据库上执行常见SQL语句(截图) 2 ... 
- Java课程设计 201521123078
			计时器 掌握java图形界面操作以及多线程技术. 1.Mythread1 写一个类Mythread1实现Runnable,当需要开一个线程时就是用这个类.其中的run()通过标记flag和循环实现时间 ... 
