dp - Google Code jam Qualification Round 2015 --- Problem B. Infinite House of Pancakes
Problem B. Infinite House of Pancakes
Problem's Link: https://code.google.com/codejam/contest/6224486/dashboard#s=p1
Mean:
有无限多个盘子,其中有n个盘子里面放有饼,每分钟你可以选择两种操作中的一种:
1.n个盘子里面的饼同时减少1;
2.选择一个盘子里面的饼,分到其他盘子里面去;
目标是让盘子里的饼在最少的分钟数内吃完,问最少的分钟数。
analyse:
可以分析出,先分再吃不会比先吃再分差,所以我们选择先分再吃。
首先用dp预处理,dp[i][j]表示:初始时为i个饼的盘子经过分以后最大值为j需要多少步。
然后我们就可以暴力+贪心了,枚举吃的次数(1~MAX),对于每一个吃的次数,我们需要把每个饼都分到小于或等于这个次数。详见代码。
Time complexity: 小于 O(n^3)
Source code:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<climits>
using namespace std; const int MAXN=;
int dp[MAXN][MAXN],a[MAXN];
void pre()
{
for(int i=;i<=MAXN;++i)
{
for(int j=;j<i;++j)
{
dp[i][j]=MAXN;
for(int k=;k<i;++k)
{
dp[i][j]=min(dp[i][j],dp[i-k][j]+dp[k][j]+);
}
}
}
}
int main()
{
pre();
int t;
scanf("%d",&t);
for(int Cas=;Cas<=t;++Cas)
{
int n;
scanf("%d",&n);
int maxx=INT_MIN;
for(int i=;i<=n;++i)
{
scanf("%d",&a[i]);
maxx=max(maxx,a[i]);
}
int ans=INT_MAX;
for(int eat=;eat<=maxx;++eat)
{
int tmp=;
for(int i=;i<=n;++i)
{
tmp+=dp[a[i]][eat];
}
tmp+=eat;
ans=min(ans,tmp);
}
printf("Case #%d: %d\n",Cas,ans);
}
return ;
}
dp - Google Code jam Qualification Round 2015 --- Problem B. Infinite House of Pancakes的更多相关文章
- Google Code jam Qualification Round 2015 --- Problem A. Standing Ovation
Problem A. Standing Ovation Problem's Link: https://code.google.com/codejam/contest/6224486/dashbo ...
- [C++]Store Credit——Google Code Jam Qualification Round Africa 2010
Google Code Jam Qualification Round Africa 2010 的第一题,很简单. Problem You receive a credit C at a local ...
- Google Code Jam 2010 Round 1C Problem A. Rope Intranet
Google Code Jam 2010 Round 1C Problem A. Rope Intranet https://code.google.com/codejam/contest/61910 ...
- [Google Code Jam (Qualification Round 2014) ] B. Cookie Clicker Alpha
Problem B. Cookie Clicker Alpha Introduction Cookie Clicker is a Javascript game by Orteil, where ...
- [Google Code Jam (Qualification Round 2014) ] A. Magic Trick
Problem A. Magic Trick Small input6 points You have solved this input set. Note: To advance to the ...
- [C++]Saving the Universe——Google Code Jam Qualification Round 2008
Google Code Jam 2008 资格赛的第一题:Saving the Universe. 问题描述如下: Problem The urban legend goes that if you ...
- Google Code Jam 2010 Round 1C Problem B. Load Testing
https://code.google.com/codejam/contest/619102/dashboard#s=p1&a=1 Problem Now that you have won ...
- Google Code Jam 2010 Round 1A Problem A. Rotate
https://code.google.com/codejam/contest/544101/dashboard#s=p0 Problem In the exciting game of Jo ...
- Google Code Jam 2010 Round 1B Problem B. Picking Up Chicks
https://code.google.com/codejam/contest/635101/dashboard#s=p1 Problem A flock of chickens are runn ...
随机推荐
- 【C++沉思录】代理类
1.考虑下面的场景:设计一个容器,包含一组类型不同但相互关联的对象(比如:Animal,Dog,Cat),对象具备多态行为.2.容器一般只能包含一种类型的对象,使用vector<Animal&g ...
- Scala 深入浅出实战经典 第60讲:Scala中隐式参数实战详解以及在Spark中的应用源码解析
王家林亲授<DT大数据梦工厂>大数据实战视频 Scala 深入浅出实战经典(1-87讲)完整视频.PPT.代码下载:百度云盘:http://pan.baidu.com/s/1c0noOt6 ...
- 如何闪开安装VS2013必须要有安装IE10的限制
把下面这一段文字,储存成.bat档案,然后右击以管理员角色去执行它.@ECHO OFF :IE10HACK REG ADD "HKLM\SOFTWARE\Wow6432Node\Micros ...
- Openvswitch原理与代码分析(5): 内核中的流表flow table操作
当一个数据包到达网卡的时候,首先要经过内核Openvswitch.ko,流表Flow Table在内核中有一份,通过key查找内核中的flow table,即可以得到action,然后执行acti ...
- DataGridView中添加CheckBox列用于选择行
DataGridView中添加CheckBox列用于选择行 1,编辑DataGridView,添加一列 CheckBox ,Name 赋值为 "select",如下图: 2,取消 ...
- NPOIHelper.cs (NPOI 2.1.1)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- win7搭建ios开发环境
安装过程参考文章: http://jingyan.baidu.com/article/ff411625b9011212e48237b4.html http://www.loukit.com/threa ...
- [初读笔记] Cloud Migration Research: A Systematic Review (TCC, 2013)
Pooyan Jamshidi, Aakash Ahmad, Claus Pahl, "Cloud Migration Research: A Systematic Review," ...
- hao.360.cn不停跳....
最近单位里访问hao.360.cn经常会跳....无限循环,有时跳几十次后才会打开.... 但是,单位里走电信出口部分的电脑就没有问题...同样的电脑(移动出口)的用360浏览器.火狐也问题不大,关键 ...
- 百度地图api根据定位获取附近商家(只获取屏幕内)
根据中心点坐标计算出屏幕2个点(一个最低经纬度,一个最高经纬度),判断这两个点中间的所有坐标的商家..考虑屏幕分辨率之类 移动地图中心点变动,如何异步刷新,判断商家是否已经存在..等... 百度地图a ...