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 ...
随机推荐
- Maven - 项目结构
一个基础的Maven Java项目结构图如下所示: Project Name |__________ pom.xml |__________ src | |__ ...
- Chapter 5. Graph Theory:: Fundamentals:: Intermediate
10457 - Magic Car 题意一开始看起来有点费解,其实最后就是要起点到终点的路径上最大边与最小边之差越小越好.这样我们可以先将边排个序,然后枚举路径上的最小边,之后依次将比它大的边按升序的 ...
- python数据结构之图深度优先和广度优先
首先有一个概念:回溯 回溯法(探索与回溯法)是一种选优搜索法,按选优条件向前搜索,以达到目标.但当探索到某一步时,发现原先选择并不优或达不到目标,就退回一步重新选择,这种走不通就退回再走的技术为回溯法 ...
- C# 百度语音合成
语音合成及TTS,我们尝试使用百度的语音合成技术 不过我发现 有一种缺点在于没有离线包让我有些很不舒服,可能是在线版的 原因微软语音识别技术在Windows 2000是默认集成在系统组件中 或许我们不 ...
- First MarkDown Blog
#First MarkDown Blog ##Title1 ##Tiltle2
- Java 中类的加载顺序
如果类A和类B中有静态变量,静态语句块,非静态变量,非静态语句块,构造函数,静态方法,非静态方法,同时类A继承类B,请问当实例化A时,类内部的加载顺序是什么? 测试代码如下: Class B: pub ...
- 使用wireshark抓取wcf生成的soap消息
在使用wcf的时候想看下生成的soap的格式是怎样的,就想到了抓包. 平时用惯的抓包工具是需要破解,另外有时会不太好用. 于是就想起来用wireshark. 首先遇到几个问题: 1.wireshart ...
- 查询反模式 - GroupBy、HAVING的理解
为了最简单地说明问题,我特地设计了一张这样的表. 一.GROUP BY单值规则 规则1:单值规则,跟在SELECT后面的列表,对于每个分组来说,必须返回且仅仅返回一个值. 典型的表现就是跟在SELEC ...
- PHP/MYSQL UTF8 中文排序
1. 需要在php数组中用中文排序,但是一般使用utf8格式的文件,直接用asort排序不行.用gbk和gb2312可以.这跟几种格式的编码有关系.gbk和gb2312本身的编码就是用拼音排序的. f ...
- LintCode-- Remove Linked List Elements
Remove all elements from a linked list of integers that have valueval. 样例 Given 1->2->3->3- ...