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的更多相关文章

  1. 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 ...

  2. [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 ...

  3. 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 ...

  4. [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 ...

  5. [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 ...

  6. [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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. android:style.xml

    <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2006 The Andr ...

  2. .NET Actor Model Implementations Differ in Approach

    Last week Vaughn Vernon, author of Implementing Domain-Driven Design, published Dotsero, a .NET Acto ...

  3. 360随身WiFi驱动下载

    一场不算太好的体验,但还是解决问题了 360随身WiFi驱动下载地址 事情经过: 某天在家里组装起PC,才发现当时没有在这屋里预留网线接口,走明线穿堂过户肯定是不合适的,还是买个无线网卡吧 自然还是要 ...

  4. UML 六种关系

    .继承, 男人 和 人 的关系2.实现, 孕妇 和 生宝宝 的关系3.依赖, 人 和 大米.水4.关联, 男人 和 工作5.聚合, 弱整体和部分, 轮子和车6.组合, 强整体和部分, 眼睛和人 参考: ...

  5. 删除.gitignore中的在version control中的文件

    如果有一个文件例如xyz在版本控制系统中,然后你发现这个文件不应该提交到git上,所以加了.gitignore文件并将其加入其中,但是git不会自动讲其从版本库中移除它.如果你只有一个文件,你可以使用 ...

  6. hibernate下载包中配置文件路径

    路径:hibernate-release-5.0.2.Final\project\hibernate-ehcache\src\test\resources\hibernate-config 文件:hi ...

  7. caffe上使用hdf5格式文件以及回归(regression)问题

    最近用caffe做了一下regression问题,先用data layer中的data,float_data试了一下,data用来存放图片,float_data存放regression的values, ...

  8. 开发常用到的terminal命令

    1.删除work_plugin目录下的.svn文件(最后面的;也是命令的一部分) sudo find /Users/maxinliang/DaTang/work_plugin ".svn&q ...

  9. nginx+lua_nginx+GraphicsMagick生成实时缩略图

    暂做笔记,带后续验证通过后,再补充 1.2.3 步. 一.安装 lua 首先确认是否安装 readline yum -y install readline-devel ncurses-devel 进入 ...

  10. java实例练习

    1.不使用中间变量交换两个数 public class Exchange { public static void main(String[] args) { Scanner scanner = ne ...