100722E The Bookcase
题目大意
给你一些书的高度和宽度,有一个一列三行书柜,要求放进去书后,三行书柜的高的和乘以书柜的宽度最小。问这个值最小是多少。
分析
我们可以先将所有书按照高度降序排好,这样对于每一层只要放过书高度边不会改变。我们设第一本书放在第一层,用dp[i][j][k]表示考虑到第i个,第二层的厚度为j,第三层的厚度为k的情况时书架的最小总高度是多少,如果j或k是0则代表这一层以前没放过书,然后根据这个转移就行了。由于空间不够我们使用滚动数组。注意由于至少有三本书,所以每一层至少会放一个(这样可以使答案更优)。
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define gmin(x,y) x=min(x,y)
const int inf = 0x3f3f3f3f;
struct node {
int h,w;
};
node d[];
int dp[][][],maxw[];
inline bool cmp(const node x,const node y){return x.h>y.h;}
int main(){
int n,m,i,j,k,t;
scanf("%d",&t);
while(t--){
memset(maxw,,sizeof(maxw));
scanf("%d",&n);
for(i=;i<=n;i++){
scanf("%d%d",&d[i].h,&d[i].w);
}
sort(d+,d+n+,cmp);
maxw[]=d[].w;
for(i=;i<=n;i++)
maxw[i]=maxw[i-]+d[i].w;
int now=;
memset(dp[now],0x3f,sizeof(dp[now]));
dp[now][][]=d[].h;
for(i=;i<=n;i++){
now^=;
memset(dp[now],0x3f,sizeof(dp[now]));
for(j=;j<=maxw[i-];j++)
for(k=;k+j<=maxw[i-];k++)
if(dp[now^][j][k]<inf){
gmin(dp[now][j][k],dp[now^][j][k]);
if(!j)gmin(dp[now][j+d[i].w][k],dp[now^][j][k]+d[i].h);
else gmin(dp[now][j+d[i].w][k],dp[now^][j][k]);
if(!k)gmin(dp[now][j][k+d[i].w],dp[now^][j][k]+d[i].h);
else gmin(dp[now][j][k+d[i].w],dp[now^][j][k]);
}
}
int ans=inf;
for(i=;i<=maxw[n];i++)
for(j=;j+i<=maxw[n];j++){
k=maxw[n]-i-j+d[].w;
if(dp[now][i][j]<inf)
gmin(ans,(dp[now][i][j])*max(i,max(j,k)));
}
printf("%d\n",ans);
}
return ;
}
100722E The Bookcase的更多相关文章
- CodeForces #368 div2 D Persistent Bookcase DFS
题目链接:D Persistent Bookcase 题意:有一个n*m的书架,开始是空的,现在有k种操作: 1 x y 这个位置如果没书,放书. 2 x y 这个位置如果有书,拿走. 3 x 反转这 ...
- 【Codeforces-707D】Persistent Bookcase DFS + 线段树
D. Persistent Bookcase Recently in school Alina has learned what are the persistent data structures: ...
- Codeforces Round #368 (Div. 2) D. Persistent Bookcase
Persistent Bookcase Problem Description: Recently in school Alina has learned what are the persisten ...
- 【暑假】[深入动态规划]UVa 10618 The Bookcase
UVa 12099 The Bookcase 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=42067 思路: ...
- Persistent Bookcase
Persistent Bookcase time limit per test 2 seconds memory limit per test 512 megabytes input standard ...
- 新概念英语(1-37)Making a bookcase
What is Susan's favourite color ? A:You're working hard, Georage. What are you doing? B:I am making ...
- Codeforces Round #368 (Div. 2) D. Persistent Bookcase 离线 暴力
D. Persistent Bookcase 题目连接: http://www.codeforces.com/contest/707/problem/D Description Recently in ...
- codeforces 707D:Persistent Bookcase
Description Recently in school Alina has learned what are the persistent data structures: they are d ...
- codeforces 707D D. Persistent Bookcase(dfs)
题目链接: D. Persistent Bookcase time limit per test 2 seconds memory limit per test 512 megabytes input ...
随机推荐
- 20165210 Java第三次实验报告
20165210 实验二 敏捷开发与XP实践 一.敏捷开发与XP实践-1 实验要求: http://www.cnblogs.com/rocedu/p/4795776.html, Eclipse的内容替 ...
- Python_单元测试工具nose
一.nose的API nose的API地址:http://pythontesting.net/framework/nose/nose-introduction/ 二.安装nose 先用easy_ins ...
- git教程2-删除修改和文件
文件处于三种状态: 1.位于工作区,未修改状态: 2.位于工作区,已经修改状态: 3.位于暂存区,已经暂存但未commit. 4.已经commit. 一.文件删除修改: 1.已经修改,但未add: g ...
- python主函数
Python的人会很不习惯Python没有main主函数. 这里简单的介绍一下,在Python中使用main函数的方法 #hello.py def foo(): str="function& ...
- vs2012 sln和.vcxproj有什么区别
sln是解决方案的配置,主要是管理这个方案里的多个vcxprojvcxproj是工程的配置文件,管理工程中细节比如包含的文件,引用库等一般没有sln,也可以直接打开vcxproj,也可以重新生成sln ...
- Python日志统计
#!/usr/bin/env python # coding:utf-8 import sys,time class DisplayFormat(object): def form ...
- Android Studio 学习 - Activity生命周期
落下两晚了,继续学习…… 先粘贴2张官方给的流程图: ------------------------------------------------------------------------- ...
- MySQL下分页查询数据
-- 分页 -- 前两条 -- 启始位置从下标0开始,查询的是数据库中的第1条开始 -- 0:启始位置 2:一次性查询多少条 select * from account LIMIT 0,2; -- ...
- python之 python 起源、语言特点
一. 1.1 什么是 PythonPython 是一门优雅而健壮的编程语言,它继承了传统编译语言的强大性和通用性,同时也借鉴了简单脚本和解释语言的易用性.它可以帮你完成工作,而且一段时间以后,你还能 ...
- springmvc 加载静态文件失败
header.jsp,部分代码 <head> <title>QA|VIS_PLATFORM</title> <meta content="width ...