POJ 2901 Hotel

Tomcat漏洞——弱口令爆破 靶机:CentOS7 IP:192.168.100.40。攻击机:kali IP:192.168.100.60。版 权 声 明:本博客所有文章除特别声明外,均采用。文章版权归作者所有,未经允许请勿转载!作 者:PeiyuJue。 阅读详情

 

http://acm.pku.edu.cn/JudgeOnline/problem?id=2901
Hotel
Time Limit: 10000MS Memory Limit: 65536K
Total Submissions: 561 Accepted: 156

Description

Zebel, the tour coordinator, has reserved a limited number of hotel rooms for his clients. Rooms have different capacities and naturally, different prices. Zebel decides to find the least cost assignment of the tour participants to the available rooms. His strategy is to fill the rooms with appropriate collection of people to minimize the overall room cost, but he is facing some restrictions that no two people of different sex that are not married may stay in the same room, and if a room is assigned to a married couple, no other person may stay in that room. Note that it is not necessary to put a married couple in the same room. It is also possible that we do not fill a room to its capacity. 

You are to write a program to help Zebel find a least cost assignment of the tour participants to the reserved hotel rooms. 

Input

The only number in the first line is t, the number of test cases that follow. The first line of each test case contains four integer numbers, 0 ≤ m ≤ 500 the number of male tour participants, 0 ≤ f ≤ 500 the number of female tour participants, 0 ≤ r ≤ 500 the number of rooms reserved by Zebel, and c ≥ 0 which is the number of marriage relations between tour participants. Note that polygamy is not allowed in the tour; i.e. each participant is either single or has a unique mate. 

The description of the reserved rooms comes on the following r lines. Each line describes a room, by two integer numbers 1 ≤ bi ≤ 5, and 1 ≤ pi ≤ 1000, which are the capacity and price of this room. 

Output

For each test case in the input, output the minimum cost of assigning the rooms to the tour participants. If this is not possible, output the phrase "Impossible" instead. 

Sample Input

2
2 1 3 1
3 5
2 10
2 4
1 1 1 0
1 4

Sample Output

9
Impossible

Source

/*
(1)这题一开始想到的是贪心,方法是:根据当前剩余的male,female,couple数来求每个房价的最大单人价格,即用
房间的价格除以这个房间可以放入的实际人数,然后取最大值的房间放入人数,一直取到所有房间都被用上或者
剩余的male,female,couple数是0,但是这样做后来经过验证是不正确的,这个问题不具备贪心性质,因为当前最
优不能保证全局最优,所以不能用贪心进行求解
(2)后来想到的是贪心不行的话,动态规划肯定行。但是动态规划的问题是可能超时,因为有四维(room, male,female,couple)
这样就是n ^ 4,肯定会超时。后来看到讨论里面有人给了个提示,可以将couple那一维的上限减少到最多是1,因为设想
假如一共分了k(k >= 2)个房间给所有couple,那么我们总可以通过将所有couple中的男子放在一起住以及将所有女子放在
一起住来减少房间的使用量,这样总的消费数肯定不超过原来的消费数。至于为什么有可能需要开出一个房间给一对couple,
是为了避免如下情况:假设有三对couple,分别放在容量为2,2,2的三个房间中,那么肯定只能合并处理两队couple了。基于
(3)通过以上分析可以将couple维的上限减少到1.那么这个就是一个典型的背包问题了
dp(rp, mp, fp, cp)表示利用1~rp个房间,放入mp,fp,cp可以取得的最小费用,则
if(rp >= 1) 则dp(rp, mp, fp, cp) = minv(dp(rp, mp, fp, cp), dp(rp - 1, mp - minv(cap(rp), fp, mp) + price(rp))
if(mp >= 1) 则dp(rp, mp, fp, cp) = minv(dp(rp, mp, fp, cp), dp(rp - 1, mp, fp - minv(cap(rp), fp) + price(rp))
if(cp >= 1 && cap(rp) >= 2)  则dp(rp, mp, fp, cp) = minv(dp(rp, mp, fp, cp), dp(rp - 1, mp - 1, fp - 1, 0) + price(rp))
上面三种情况分别为在当前屋子放入男子,放入女子,放入couple
由于每个dp(rp)状态只与dp(rp - 1)有关,因此可以利用倒序遍历减少存储空间,即存储空间开辟为dp[m][f][2],遍历的时候
第一层循环从1致r, 第二层循环从m致0,第三层循环从f致0,第四层循环从1致0即可,在每个第一层结束的时候取dp[m][f][0],dp[m - 1][f - 1][1]
中的最小者即为最后所求
(4)初始化:dp[0][0][0]初始化为1,其他所有值初始化为最大值即可
*/
 
STM32CubeMX之emWin移植 “前面两章介绍了SDRAM和LTDC的使用,本篇文章将介绍emWin移植到STM32。”硬件环境:STM32F429IGT6软件环境:STM32CubeMX v5.5.0... 阅读详情

相关推荐

Lumerical官方案例、FDTD时域有限差分法仿真学习(十四)——超透镜(Metalens)

这个例子的目的是设计一个由圆柱形纳米棒组成的衍射超透镜。 纳米棒的半径和排列经过调整以在超透镜表面上产生所需的相位分布。 该设计通过近场和远场分析在 Ansys FDTD、RCWA(严格耦合波分析)和 OpticStudio 中得到验证。...

weixin_45719141的博客 3万+

POJ 2901 Hotel 笔记

m位男游客,f位女游客,r个房间,c对夫妇。每个房间 i 能住 bi 个人,费用是 pi 。夫妇可住同一房间,不能与其他人同住。未婚男女不能混住。求最少的住宿花费。

woniupengpeng的专栏 307

6、高通8155座舱平台--摄像头系统

在项目中遇到过,很多从手机转过来的工程师,上来就按手机那套调Camera,结果发现根本跑不通——为什么?我踩过这个坑——一开始想靠软件打时间戳来对齐,结果发现两个sensor的曝光时间不一样,时间戳根本对不上。我记得第一次调AWB时,怎么调颜色都不对,后来发现是BLC的参数没配好——黑电平偏了,后面所有颜色校正都是错的。上层应用说「我要拍张照」,HAL把它翻译成「ISP你给我处理这帧数据,sensor你给我曝光一次」。8155上推荐用camx,它是高通新一代的Camera框架,性能更好,而且支持多路同步。

woailuojp的博客 66

POJ 2901——Hotel

题目大意:n个男人,m个女人,其中夫妻c对,旅社有r房间,不同的房间有自己能住的人数和价格;                     男人能跟男人住一起,女人能跟女人住一起,或者夫妻两人单独一个房间(夫妻两人不一定非要住一起)                   简单的一道dp题,一看就知道最多一对夫妻单独住,看下面的解释 比如男 5 女 3 夫妻 2 那么可以有两组 5 3 或者

HH_YT的专栏 930

20.Labview使用子vi进行VI间的数据传递详解(模块化)

子VI(模块化)题主在题注中也提到, 子VI的建立只是为了减少程序的负担,那么我们当使用子VI的时候首先就要明确什么是子VI?什么样的程序可以作为子VI?首先我们来看NI官方给的定义,具体说明如下图所示:题主已经将重点画出来了,在官方的解释中将子VI定义为了模块化,大家可以看到创建模块化子VI的特点在于减少代码重复工作优化了程序的框架结构。把一个代码打包,需要的时候就拎出来让他处理处理,不需要的时候就让它躺在我的列表里就行了也不占用运行空间。那么创建子VI需要需要注意以下几点:①任何一个程序。

关注我,更多技术问题欢迎私聊~ 3524

CKS-CN考试之路----03

这题不需要去生成image和生成deployment所以只需要去检测对应的值即可。编辑/cks/docker/Dockerfile,修改最后第二行的值。编辑/cks/docker/deployment.yaml。

Q先生 838

POJ 刷题顺序

POJ从简到难(按照AC数目排序)的列表如下,作为小弱的刷题

thestoryofsnow的专栏 31万+

教师模型与学生模型:知识蒸馏的核心概念

知识蒸馏,教师模型,学生模型,模型压缩,迁移学习,深度学习 1. 背景介绍 深度学习模型在图像识别、自然语言处理等领域取得了显著的成就,但其巨大的模型规模和高昂的计算成本限制了其在资源有限的设备上的部署。知识蒸馏(Knowledge Distillation)作为一种模型压缩技术,旨

AI架构师小马 2790

poj2901 Hotel

Hotel Time Limit:10000MS Memory Limit:65536K Total Submissions:859 Accepted:280 Description Zebel, the tour coordinator, has reserved a limited number of hotel room...

weixin_30947043的博客 148

OData V2 消息在 SAP UI5 中的生成、传播与治理全解

SAP UI5 的 OData V2 消息机制通过自动解析服务端响应头(sap-message)或错误体,将消息推送到全局 MessageModel,实现数据质量保障。关键点包括:1)消息通过目标路径与控件绑定联动,触发高亮等反馈;2)生命周期管理需注意避免自动刷新导致消息丢失;3)常见陷阱如批处理错误重复、内外层消息冲突等可通过精准目标路径或自定义处理器解决。代码示例展示了如何配置模型、消息模型及 MessagePopover 实现端到端消息展示,同时支持控件通过 refreshDataState 自定义

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 242

HyperLynx(十五)多板仿真

在对话框的“Design file#1”下拉列表中选择“B00,Mainboard”,在其下方的“Reference designators”列表中选择元器件“J1”,然后在“Designfile#2”下拉列表中选择“BO1、RAM1”,在其下方的“Refer ence designators”列表中选择元器件“J1”,单击“Insert”按钮,为这两个元器件建立互连映射。在“Assign Models”对话框中,选择“B00 Motherboard”,将“U16.B12”设置为输出。

小幽余生不加糖 5074

GOOGLE的一道笔试题—求给定连通无环无向图可以生成的最小高度树

/*最近看到一道谷歌笔试题,“已知一颗无向无环连通图T的所有顶点和边的信息,现需要将其转换为一棵树,要求树的深度最小,请设计一个算法找到所有满足要求的树的根结点,并分析时空复杂度(描述算法即可,无需代码)”其实就是给定一个无向连通图,求以哪些顶点为根可以得到深度最小的树,思路比较简单,主要有两个步骤:(1)首先选取1号结点作为树根,进行一遍DFS,在DFS时计算每个节点

bobten2008的专栏 3709

windows 配置 libxml2

路径:\libiconv-1.9.2-1-src.zip\src\libiconv\1.9.2\libiconv-1.9.2\include\。执行完后,在当前win32目录中会生成了一个bin.msvc目录,其中就有开发需要的libxml2.lib和libxml2.dll文件。将 libiconv.la 复制到 新建的 lib 目录,并将其改名为 iconv.lib。路径:libiconv-1.9.2-1-bin.zip\lib\。将如下的 iconv.h 复制到新建的 include 目录。

SHELLCODE_8BIT的博客 3894

POJ 1952 BUY LOW BUY LOWER 【DP】最长降序子序列及其计数问题

 BUY LOW, BUY LOWERTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 4981 Accepted: 1663DescriptionThe advice to "buy low" is half the formula to success

bobten2008的专栏 2271

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

POJ 1191棋盘分割

 棋盘分割Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 5827 Accepted: 2092>>Description将一个8*8的棋盘进行如下分割:将原棋盘割下一块矩形棋盘并使剩下部分也是矩形,再将剩下的部分继续如此分割,这样割了(n-1)次

bobten2008的专栏 2235

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

POJ 1085 Triangle War

Triangle WarTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 1465 Accepted: 582DescriptionTriangle War is a two-player game played on the following trian

bobten2008的专栏 2100

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

POJ 1934 Trip LCA及其所有不重复的串

 TripTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 1629 Accepted: 372DescriptionAlice and Bob want to go on holiday. Each of them has planned a route,

bobten2008的专栏 2027

POJ 1661 Help Jimmy

Help JimmyTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 5993 Accepted: 1840Description"Help Jimmy" 是在下图所示的场景上完成的游戏。 场景中包括多个长度和高度各不相同的平台。地面是最低的平台,高度为零,长度

bobten2008的专栏 1842

POJ 1732 Phone numbers

 Phone numbersTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 2456 Accepted: 852 Special JudgeDescriptionIn the present world you frequently meet a

bobten2008的专栏 1715

POJ 1112 Team Them Up

Team Them Up!Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 3404 Accepted: 901 Special JudgeDescriptionYour task is to divide a number of persons i

bobten2008的专栏 1558

POJ 2030 The Secret Number

 The Secret NumberTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 1704 Accepted: 564DescriptionYour job is to find out the secret number hidden in a mat

bobten2008的专栏 1375

POJ 1874 Trade on Verweggistan

Trade on VerweggistanTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 1238 Accepted: 355DescriptionSince the days of Peter Stuyvesant and Abel Tasman, Du

bobten2008的专栏 1302

POJ 1692 Crossed Matchings

 Crossed MatchingsTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 1578 Accepted: 1020DescriptionThere are two rows of positive integer numbers. We can d

bobten2008的专栏 1217

POJ 1964 & 1494

 City GameTime Limit: 3000MS Memory Limit: 30000KTotal Submissions: 3095 Accepted: 1181DescriptionBob is a strategy game programming specialist. In his new city b

bobten2008的专栏 1215

POJ 2019 Cornfields

 CornfieldsTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 3096 Accepted: 1459DescriptionFJ has decided to grow his own corn hybrid in order to help the

bobten2008的专栏 1130

POJ 1505 Copying Books

 Copying BooksTime Limit: 3000MS Memory Limit: 10000KTotal Submissions: 4431 Accepted: 1256DescriptionBefore the invention of book-printing, it was very hard to m

bobten2008的专栏 1102
上一篇: POJ 2900 Griddy Hobby
下一篇: POJ 2902 Intercepting Missiles
bobten2008
博客等级 码龄18年 153粉丝 157原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值