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. iOS中的webView加载HTML

    在日常开发中,我们为了效率会用到很多很多的WebView,比如在做某个明细页面的时候我们返回给你的可能是一个html字符串,我们就需要将当前字符串展示到webView上面,所以我们对HTML标签需要有 ...

  2. SQL 性能调优日常积累【转】

    阅读目录 (1)选择最有效率的表名顺序(只在基于规则的优化器中有效) (2)WHERE子句中的连接顺序 (3)SELECT子句中避免使用 ‘ * ‘ (4)减少访问数据库的次数 (5)在SQL*Plu ...

  3. word2007二级标题自动编号不从大标题开始的解决方法

    今天在编写word文档的时候,遇到一个很奇怪的问题,word2007二级标题自动编号不从大标题开始,可能我说的比较模糊,我截个图大家一看就明白了. 我想要的是2.1 2.2结果,他确是从1.1开始了. ...

  4. Windows下修改Oracle默认的端口1521

    数据库最好不对公网开放,如果要开放,最好把默认端口改掉,防止一些针对 1521端口的入侵 1.找到 product\11.2.0\dbhome_1\NETWORK\ADMIN 下面的  listene ...

  5. MYSQL校对规则

    一.前言 有时候遇到这种情况,你用一个like语句查询,查到的结果中有一些并没有包含你查询的关键词的纪录:有时候遇到这种情况,你的数据库自作聪明的大小写不敏感,让你在更新时把大小写不同的两条记录都更新 ...

  6. SQL语句 - 基本查询

    select select_list [ into new_table ] from table_source [ where search_condition ] [ group by broup_ ...

  7. Java帮助文档的生成

    首先需要对代码加上文档的注释,比如下面这样: package wz.learning;        /**   * Title:Person<br>   * Description:  ...

  8. NFS挂载Android文件系统

    NFS挂载Android文件系统 [日期:2012-02-14] 来源:Linux社区  作者:cjok376240497 [字体:大 中 小]     1.安装NFS服务 $sudo apt-get ...

  9. How to debug Typescript in browser

    How to debug typescript, In Chrome, we need to press F12, open settings, uncheck the Enable JavaScri ...

  10. java-Filter

    java-Filter 过滤器是小型的Web组件,它们负责拦截请求以及响应,以便查看.提取或以某种方式操作正在客户机和服务器之间交换的数据.简单的说,过滤器就类似于客户端发送的web请求与服务器之间的 ...