POJ 1946 Cow Cycling
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 2516 | Accepted: 1396 |
Description
Like everyone else, cows race bicycles in packs because that's the most efficient way to beat the wind. While travelling at x laps/minute (x is always an integer), the head of the pack expends x*x energy/minute while the rest of pack drafts behind him using
only x energy/minute. Switching leaders requires no time though can only happen after an integer number of minutes. Of course, cows can drop out of the race at any time.
The cows have entered a race D (1 <= D <= 100) laps long. Each cow has the same initial energy, E (1 <= E <= 100).
What is the fastest possible finishing time?
Only one cow has to cross the line. The finish time is an integer. Overshooting the line during some minute is no different than barely reaching it at the beginning of the next minute (though the cow must have the
energy left to cycle the entire minute). N, D, and E are integers.
Input
Output
Sample Input
3 30 20
Sample Output
7
Hint
[as shown in this chart: leader E pack total used this time leader speed dist minute 1 1 5 5 25 2 1 2 7 4 3 2* 4 11 16 4 2 2 13 4 5 3* 3 16 9 6 3 2 18 4 7 3 2 20 4 * = leader switch
Source
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#define N 110
#define INF 0x7ffffff
using namespace std;
int dp1[N][N][N];
int dp[N][N][N];
bool ch[N][N][N];
int main()
{
//freopen("data.txt","r",stdin);
int dfs(int n,int m,int k);
int n,m,k;
while(scanf("%d %d %d",&n,&m,&k)!=EOF)
{
for(int i=0;i<=k;i++)
{
for(int j=0;j<=i;j++)
{
for(int z = 0;z<=m;z++)
{
dp1[i][j][z]=INF;
}
}
}
for(int z= 0;z<=m;z++)
{
dp1[0][0][z] = 0;
}
for(int i=1;i<=k;i++)
{
for(int j=0;j<=m;j++)
{
dp1[i][0][j] = 0;
}
}
for(int i=1;i<=k;i++)
{
for(int j=1;j<=i;j++)
{
for(int z=1;z<=m;z++)
{
for(int v=1;v*v<=z&&v<=j;v++)
{
dp1[i][j][z] = min(dp1[i][j][z],dp1[i-v][j-v][z-v*v]+1);
}
}
}
}
memset(ch,false,sizeof(ch));
dfs(n,k,m);
if(dp[n][k][m]>=INF)
{
printf("0\n");
}else
{
printf("%d\n",dp[n][k][m]);
}
}
return 0;
}
int dfs(int n,int m,int k)
{
if(ch[n][m][k])
{
return dp[n][m][k];
}
if(n==1)
{
ch[n][m][k] = true;
dp[n][m][k] = dp1[m][m][k];
return dp1[m][m][k];
}
int Min = INF;
for(int i=0;i<=m;i++)
{
if(dp1[m][i][k]!=INF)
{
int w = dfs(n-1,m-i,k-i);
Min = min(Min,w+dp1[m][i][k]);
}
}
ch[n][m][k] = true;
dp[n][m][k] = Min;
return Min;
}
POJ 1946 Cow Cycling的更多相关文章
- POJ 1946 Cow Cycling(抽象背包, 多阶段DP)
Description The cow bicycling team consists of N (1 <= N <= 20) cyclists. They wish to determi ...
- poj 1964 Cow Cycling(dp)
/* 一开始想的二维的 只维护第几只牛还有圈数 后来发现每只牛的能量是跟随每个状态的 所以再加一维 f[i][j][k]表示第i只牛 领跑的j全 已经消耗了k体力 转移的话分两类 1.换一只牛领跑 那 ...
- [USACO2002][poj1946]Cow Cycling(dp)
Cow CyclingTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 2468 Accepted: 1378Description ...
- POJ 3045 Cow Acrobats (贪心)
POJ 3045 Cow Acrobats 这是个贪心的题目,和网上的很多题解略有不同,我的贪心是从最下层开始,每次找到能使该层的牛的风险最小的方案, 记录风险值,上移一层,继续贪心. 最后从遍历每一 ...
- poj 3348 Cow 凸包面积
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8122 Accepted: 3674 Description ...
- Cow Cycling 动态规划
1552: Cow Cycling 时间限制(普通/Java):1000MS/10000MS 内存限制:65536KByte总提交: 39 测试通过:20 描述 The ...
- POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包)
POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包) Description N (1 ≤ N ...
- POJ 3176 Cow Bowling(dp)
POJ 3176 Cow Bowling 题目简化即为从一个三角形数列的顶端沿对角线走到底端,所取得的和最大值 7 * 3 8 * 8 1 0 * 2 7 4 4 * 4 5 2 6 5 该走法即为最 ...
- POJ 2184 Cow Exhibition【01背包+负数(经典)】
POJ-2184 [题意]: 有n头牛,每头牛有自己的聪明值和幽默值,选出几头牛使得选出牛的聪明值总和大于0.幽默值总和大于0,求聪明值和幽默值总和相加最大为多少. [分析]:变种的01背包,可以把幽 ...
随机推荐
- CSS:CSS 盒子模型
ylbtech-CSS:CSS 盒子模型 1.返回顶部 1. CSS 盒子模型 CSS 盒子模型(Box Model) 所有HTML元素可以看作盒子,在CSS中,"box model&quo ...
- (9)centos7 安装与解压
1.zip/unzip zip 新file 旧file或文件夹 # 把旧文件和文件夹压缩成新文件 -r是文件夹下所有文件 zip -r a.zip ./doc #压缩当前目录 doc下的所有文件变成 ...
- 深入分析Synchronized原理
前言 记得开始学习Java的时候,一遇到多线程情况就使用synchronized,相对于当时的我们来说synchronized是这么的神奇而又强大,那个时候我们赋予它一个名字“同步”,也成为了我们解决 ...
- redis数据结构之SDS
简介 redis源码虽然是C语言实现的,但是Redis没有直接采用C语言传统的字符串表示,而是构建了一种名叫简单动态字符串(simple dynamic string,SDS)的抽象类型,并将SDS用 ...
- JQ基本
jQuery的入口函数: 特点:1. 等着DOM结构渲染完毕即可执行内部代码,不必等到所有外部资源加载完毕,jQuery帮我们完成了封装. 2. 相当于原生js中的DOMContentLoaded. ...
- Linux下的Ngnix服务器部署静态页
一.安装FTP vsftpd 的名字代表”very secure FTP daemon”, 安全是它的开发者 Chris Evans 考虑的首要问题之一.在这个 FTP 服务器设计开发的最开始的时候, ...
- Android基础——框架模式MVC在安卓中的实践
本篇文章包含以下内容: MVC的介绍 MVC的实践 MVC的介绍 MVC (Model View Controller),是模型(model)视图(view)控制器(controller)的缩写,一种 ...
- linux常用命令-3文件与目录相关命令
cd .. #返回上一级目录 cd ../.. #返回上两级目录 cd - #返回上次所在目录 cp file1 file2 #将file1复制为file2 cp -a dir1 dir2 #复制一个 ...
- LGV定理 (CodeForces 348 D Turtles)/(牛客暑期多校第一场A Monotonic Matrix)
又是一个看起来神奇无比的东东,证明是不可能证明的,这辈子不可能看懂的,知道怎么用就行了,具体看wikihttps://en.wikipedia.org/wiki/Lindstr%C3%B6m%E2%8 ...
- tcmalloc jemalloc 和ptmalloc 对比
ptmalloc 是glibc的内存分配管理 tcmalloc 是google的内存分配管理模块 jemalloc 是BSD的提供的内存分配管理 三者的性能对比参考从网上的一个图如下: 自己测试了一下 ...