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 ...
随机推荐
- JdbcTemplate queryForMap EmptyResultDataAccessException
JdbcTemplate的queryForMap方法报错 queryForMap方法使用不当,就会出错,使用方式如下: The queryForMap method in JdbcTemplate o ...
- JS图片切换效果
源地址:http://www.codefans.net/jscss/code/4699.shtml <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1 ...
- HDU 4759 Poker Shuffle
Poker Shuffle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- 【原】Jqxgrid在Java服务器端分页
研究这个后台分页一天多,特此写个文章记录备忘 jsp页面中有两个需要注意的地方:一个是source中beforeprocessing,另一个是rendergridrows中数据的获取. 说明:grid ...
- 表格类似Excel
只是很简单的实现表格,使用GridView控件-->可以上下左右滚动,但是不能合并 直接上代码: 1.主要布局 <?xml version="1.0" encoding ...
- T-SQL 公用表表达式(CTE)
公用表表达式(CTE) 在编写T-SQL代码时,往往需要临时存储某些结果集.前面我们已经广泛使用和介绍了两种临时存储结果集的方法:临时表和表变量.除此之外,还可以使用公用表表达式的方法.公用表表达式( ...
- 修改CMD的编码
修改CMD的编码 使用chcp命令,格式为chcp [nnn]后面3位数字为codepage number.简体中文为936UTF8 为 65001United States 为 437
- hadoop 转
detailed http://wenku.baidu.com/view/c2d1ebb4ba0d4a7302763a84.html http://hadoop.apache.org/docs/r1. ...
- iOS开发之应用内检测手机锁屏,解锁状态
iPhone的锁屏监测分为两种方式监听: 1. 程序在前台,这种比较简单.直接使用Darwin层的通知就可以了: #import <notify.h> #define Notificati ...
- Subgradient Algorithm
Subgradient是一种可以优化不可微的凸函数的方法. 首先回顾凸函数的定义: $f(y) \geq f(x) + \nabla f(x)^T(y-x), all \hspace{2 pt} x, ...