博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Relocation 状态压缩DP
阅读量:6229 次
发布时间:2019-06-21

本文共 3132 字,大约阅读时间需要 10 分钟。

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

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

26 12 133 9 13 3 10 117 1 1001 2 33 50 50 67 98

Sample Output

Scenario #1:2Scenario #2:3
1 #include 
2 #include
3 #include
4 #include
5 using namespace std; 6 int c1,c2,vi[110],a[30],n,dp[1100]; 7 bool check(int x) 8 { 9 int i,j,sum=0;10 memset(vi,0,sizeof(vi));11 vi[0]=1;12 for(i=0;i
=a[i];j--)18 if(vi[j-a[i]])19 vi[j]=1;20 }21 }22 for(i=c1;i>=0;i--)23 {24 if(vi[i]&&sum-i<=c2)return 1;25 }26 return 0;27 }28 int main()29 {30 int t,i,j,b[(1<<11)],bn,sum,cas=1;31 scanf("%d",&t);32 while(t--)33 {34 sum=0;35 scanf("%d%d%d",&n,&c1,&c2);36 if(c1>c2)swap(c1,c2);37 for(i=0;i
=0;j--)50 if((b[i]|j)==j)51 dp[j]=min(dp[j],dp[b[i]^j]+1);52 }53 cout<<"Scenario #"<
<<":"<
View Code

 

转载于:https://www.cnblogs.com/ERKE/p/3841959.html

你可能感兴趣的文章
tomcat虚拟主机 server.xml文件配置
查看>>
Capture Nx
查看>>
OC中的NSSet(集合)
查看>>
马士兵教学语录
查看>>
计算机网络与Internet应用
查看>>
每天一个linux命令-mkdir
查看>>
四天精通shell编程(二)
查看>>
标签制作软件中如何导出标签模板为PDF文件?
查看>>
Linux运维系统工程师系列---22
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
域结构的网络
查看>>
mysql 命令
查看>>
Oracle 11g rac 生产环境部署详录
查看>>
web.xml 中<taglib>报错
查看>>
Linux文件系统上的特殊权限(SUID、SGID、Sticky)的知识点
查看>>
零部件表设计 T_AIS_BASE_PARTS_INFO
查看>>
fgsdf
查看>>
一、Asp.Net MVC4.0开发CMS系统案例之数据库设计
查看>>
Vue.js 2.x笔记:路由Vue Router(6)
查看>>