Relocation

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Submit Status

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:

  1. At their old place, they will put furniture on both cars.
  2. Then, they will drive to their new place with the two cars and carry the furniture upstairs.
  3. 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 nC1 and C2C1 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;
}
}

最新文章

  1. [LeetCode] Spiral Matrix II 螺旋矩阵之二
  2. ex2-注释和井号
  3. CK表达式编辑器
  4. Codeforces Round #312 (Div. 2)B. Amr and The Large Array 暴力
  5. 数字签名.sys文件的步骤
  6. 在Spring aop中的propagation的7种配置的意思
  7. java猜数字小游戏
  8. VMware vSphere 服务器虚拟化之二十二桌面虚拟化之创建View Composer链接克隆的虚拟桌面池
  9. Notifications(通知)
  10. lua 模块
  11. Android学习笔记-ImageView(图像视图)
  12. 多态原理探究-从C++编译器角度理解多态的实现原理
  13. 为啥程序会有bug?
  14. 简单的接口测试类和测试生成报告工具HTMLTestRunner.py
  15. 尽量避免把弹窗加在window上,可以考虑把弹窗封装到控制器里面
  16. 接口自动化框架(java)--4.接口Token传递
  17. Kaldi的交叉熵正则化
  18. windows(xshell)免密码登录
  19. 编译安装php5 解决编译安装的php加载不了gd
  20. Solr优化案例分析

热门文章

  1. [2013-02-22]info入门FAQ
  2. php 学习笔记 一
  3. K/3 WISE V14.3官方原版云盘下载地址及培训PPT
  4. C#多线程的用法7-线程间的协作ManualResetEvent
  5. Java企业微信开发_09_素材管理之下载微信临时素材到本地服务器
  6. JAVA实用案例之文件导入导出(POI方式)
  7. 标题:a++和++a的区别
  8. javascript 学习笔记 -- js获取本地文件信息
  9. ionic项目ios真机部署(不需开发者账号)
  10. 201521123063 JAVA程序设计 第二周学习总结