poj2901 Hotel
| Time Limit: 10000MS | Memory Limit: 65536K | |
| Total Submissions: 859 | Accepted: 280 |
Description
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 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
Sample Input
2
2 1 3 1
3 5
2 10
2 4
1 1 1 0
1 4
Sample Output
9
Impossible
Source
/*
* Author: Joshua
* Created Time: 2014年10月06日 星期一 14时25分35秒
* File Name: poj2901.cpp
*/
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
#define maxn 515
#define inf 0x3f3f3f3f
typedef long long LL;
int T,n,m,r,c,ans;
int b[maxn],p[maxn],f[maxn][maxn]; void init()
{
scanf("%d%d%d%d",&n,&m,&r,&c);
for (int i=;i<=r;++i)
scanf("%d%d",&b[i],&p[i]);
} void updata(int&x ,int y)
{
if (y<x) x=y;
} void solve()
{
int tb,tp,tans,tk;
ans=inf;
for (int i=;i<=n+;++i)
memset(f[i],0x3f,(m+)<<);
f[][]=;
for (int i=;i<=r;++i)
{
tb=b[i];tp=p[i];
for (int t1=n+;t1>=;t1--)
for (int t2=m+;t2>=;t2--)
{
if (tb<=t1) updata(f[t1][t2],f[t1-tb][t2]+tp);
if (tb<=t2) updata(f[t1][t2],f[t1][t2-tb]+tp);
}
}
for (int i=n;i<=n+;++i)
for (int j=m;j<=m+;++j)
ans=min(ans,f[i][j]);
if (c%==) return;
tk=;
b[]=;p[]=inf;
for (int i=;i<=r;++i)
if (b[i]>= && (p[i]<=p[tk] || (p[i]==p[tk] && b[i]<b[tk])))
tk=i;
if (!tk) return;
n--;m--;
for (int i=;i<=n+;++i)
memset(f[i],0x3f,(m+)<<);
f[][]=;
for (int i=;i<=r;++i)
{
if (i==tk) continue;
tb=b[i];tp=p[i];
for (int t1=n+;t1>=;t1--)
for (int t2=m+;t2>=;t2--)
{
if (tb<=t1) updata(f[t1][t2],f[t1-tb][t2]+tp);
if (tb<=t2) updata(f[t1][t2],f[t1][t2-tb]+tp);
}
}
for (int i=n;i<=n+;++i)
for (int j=m;j<=m+;++j)
ans=min(ans,f[i][j]+p[tk]);
} int main()
{
scanf("%d",&T);
for (int i=;i<=T;++i)
{
init();
solve();
if (ans!=inf) printf("%d\n",ans);
else printf("Impossible\n");
}
return ;
}
poj2901 Hotel的更多相关文章
- POJ 3667 Hotel(线段树 区间合并)
Hotel 转载自:http://www.cnblogs.com/scau20110726/archive/2013/05/07/3065418.html [题目链接]Hotel [题目类型]线段树 ...
- ACM: Hotel 解题报告 - 线段树-区间合并
Hotel Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Description The ...
- HDU - Hotel
Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and e ...
- 【POJ3667】Hotel
Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and e ...
- POJ-2726-Holiday Hotel
Holiday Hotel Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8302 Accepted: 3249 D ...
- Method threw 'org.hibernate.exception.SQLGrammarException' exception. Cannot evaluate com.hotel.Object_$$_jvst485_15.toString()
数据库字段和类Object属性不匹配,Method threw 'org.hibernate.exception.SQLGrammarException' exception. Cannot eval ...
- poj 3667 Hotel(线段树,区间合并)
Hotel Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 10858Accepted: 4691 Description The ...
- [POJ3667]Hotel(线段树,区间合并)
题目链接:http://poj.org/problem?id=3667 题意:有一个hotel有n间房子,现在有2种操作: 1 a,check in,表示入住.需要a间连续的房子.返回尽量靠左的房间编 ...
- 【BZOJ】【3522】【POI2014】Hotel
暴力/树形DP 要求在树上找出等距三点,求方案数,那么用类似Free Tour2那样的合并方法,可以写出: f[i][j]表示以 i 为根的子树中,距离 i 为 j 的点有多少个: g[i][j]表示 ...
随机推荐
- pug模板引擎(原jade)
前面的话 为什么要引入pug,pug有什么特别之处呢?有一些嵌套层次较深的页面,可能会出现巢状嵌套,如下图所示 在后期维护和修改时,一不小心少了一个尖括号,或者某个标签的开始和闭合没有对应上,就会导致 ...
- 登录界面Demo
今天记载一个Demo,这个是我练习项目中用到,供新手看看,界面图:
- (转)Sublime Text2 快捷键汇总
场景:最近在编写项目中越发的感觉到一个得心应手的编辑器是多么的重要,而sublime,无疑是让我用着最舒服,最有感觉的编辑器了! 1 快捷键总结 一个好的编辑器,能大大提高编程的效率.如果能熟知软件的 ...
- swift3.0 CoreGraphics绘图-实现画板
swift3.0对绘图的API进行了优化,看起来更swift了. 看下UI的构造.设置画笔粗细.清空面板和保存到本地 下面直接看画板文件 这里我做的比较复杂,记录触摸到的每个点,再连成路径,其实直接用 ...
- [BZOJ1500][NOI2005]维修数列---解题报告
Portal Gun:[BZOJ1500][NOI2005]维修数列 有一段时间没写博客了,最近在刚数据结构......各种板子背得简直要起飞,题目也是一大堆做不完,这里就挑一道平衡树的题来写写好了 ...
- angularJS的$http.post请求,.net后台接收不到参数值的解决方案
JS通用部分 var shoppingCartModule =angular.module('starter', ['ionic'], function ($httpProvider) { // Us ...
- OpenFlow协议1.0及1.3版本分析
OpenFlow是SDN控制器和交换之间交流的协议,在SDN领域有着十分重要的地位. OpenFlow协议发展到现在已经经过了1.0.1.3.1.4等版本.其中1.0和1.3版本使用的是最为广泛的. ...
- css鼠标样式cursor
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Hadoop(一)Centos7虚拟机网络配置
Centos7虚拟机网络配置(桥接模式) 一 VirtualBox提供了三种工作模式,它们是bridged(桥接模式).NAT(网络地址转换模式)和host-only(主机模式). 1 桥接模式(br ...
- Qt For Android 开发环境配置
想了想,还是再写一篇关于Qt for Android开发环境配置的教程. 准备:Java jdk,Android sdk,Android adb,Android ndk,Android ant,Qt ...