Cow Cycling
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 2516   Accepted: 1396

Description

The cow bicycling team consists of N (1 <= N <= 20) cyclists. They wish to determine a race strategy which will get one of them across the finish line as fast as possible. 

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

A single line with three integers: N, E, and D 

Output

A single line with the integer that is the fastest possible finishing time for the fastest possible cow. Output 0 if the cows are not strong enough to finish the race. 

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

    我发现近期理解题意,真是该死,我理解成了最后仅仅能有一头牛通过,这样其它的牛除最后一头牛外最后的能量必须是负值。老是WA后。发现思路没错,就怀疑理解错题意。果然他要求的是仅仅要一头牛通过即可,求这头牛的最快时间,其它的牛不做要求。改了改初始话,AC了
题意:给定N头牛,每头牛的能量为E,距离为D,跑的时候假设是速度为X,则打头的牛的能量消耗为X*X/minute 其它的牛的能量消耗为X/minute 求当中一头牛到达终点时候,所用时间最少
思路:预处理出dp1[sta][end][e]:表示在能量为e的时候要跑的长度为sta,跑了end的时候用的时间最少
然后dfs+记忆化DP,枚举每头牛跑的长度。
#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的更多相关文章

  1. POJ 1946 Cow Cycling(抽象背包, 多阶段DP)

    Description The cow bicycling team consists of N (1 <= N <= 20) cyclists. They wish to determi ...

  2. poj 1964 Cow Cycling(dp)

    /* 一开始想的二维的 只维护第几只牛还有圈数 后来发现每只牛的能量是跟随每个状态的 所以再加一维 f[i][j][k]表示第i只牛 领跑的j全 已经消耗了k体力 转移的话分两类 1.换一只牛领跑 那 ...

  3. [USACO2002][poj1946]Cow Cycling(dp)

    Cow CyclingTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 2468 Accepted: 1378Description ...

  4. POJ 3045 Cow Acrobats (贪心)

    POJ 3045 Cow Acrobats 这是个贪心的题目,和网上的很多题解略有不同,我的贪心是从最下层开始,每次找到能使该层的牛的风险最小的方案, 记录风险值,上移一层,继续贪心. 最后从遍历每一 ...

  5. poj 3348 Cow 凸包面积

    Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8122   Accepted: 3674 Description ...

  6. Cow Cycling 动态规划

    1552: Cow Cycling 时间限制(普通/Java):1000MS/10000MS     内存限制:65536KByte总提交: 39            测试通过:20 描述 The ...

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

  8. POJ 3176 Cow Bowling(dp)

    POJ 3176 Cow Bowling 题目简化即为从一个三角形数列的顶端沿对角线走到底端,所取得的和最大值 7 * 3 8 * 8 1 0 * 2 7 4 4 * 4 5 2 6 5 该走法即为最 ...

  9. POJ 2184 Cow Exhibition【01背包+负数(经典)】

    POJ-2184 [题意]: 有n头牛,每头牛有自己的聪明值和幽默值,选出几头牛使得选出牛的聪明值总和大于0.幽默值总和大于0,求聪明值和幽默值总和相加最大为多少. [分析]:变种的01背包,可以把幽 ...

随机推荐

  1. Golang 标准库提供的Log(一)

      原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://gotaly.blog.51cto.com/8861157/1405754 G ...

  2. mkdir: cannot create directory ‘/soft/hadoop-2.7.3/logs’: Permission denied问题

    启动hadoop时,报错“mkdir: cannot create directory ‘/soft/hadoop-2.7.3/logs’: Permission denied” 注:/soft/ha ...

  3. csv 基本操作, 报错解决(UnicodeEncodeError: 'utf-8' codec can't encode characters in position 232-233: surrogates not allowed)

    最常用的一种方法,利用pandas包 import pandas as pd #任意的多组列表 a = [1,2,3] b = [4,5,6] #字典中的key值即为csv中列名 dataframe ...

  4. gitlab开机启动|启动 停止 重启

    修改配置后的初始化 gitlab-ctl reconfigure 启动 sudo gitlab-ctl start 停止sudo gitlab-ctl stop 重启sudo gitlab-ctl r ...

  5. 由dubbo开始看看所谓的软负载均衡

    待总结 我们在微服务架构中,常用一些注册中心进行订阅消费我们的服务,这时候对于同一服务请求会有不同的机器同时可以提供服务,这时是怎么选择哪一台机器去连接获取服务呢? 负载均衡设备作为纵跨网络2/7层交 ...

  6. 2018 最新 spring boot 整合 swagger2 (swagger2 版本 2.8.0)

    好久没上了, 看到又有人回复了. 我就来修改一下. 修改时间  2018年5月16日 这回给你上全新版本. 至发稿时间,所有的包都是新版. 注意: 高版本需要添加  jaxb-api 包, 否则会报错 ...

  7. 前端实现预览ppt,word,xls,pdf文件

    1.前端实现pdf文件在线预览功能 ps:刚好工作上有这个需求,所以到处找了一下处理方案,大家有需要可以试一下这几种方案,找到合适自己的 方式一. pdf文件理论上可以在浏览器直接打开预览但是需要打开 ...

  8. docker Dockerfile学习---构建apache环境

    1.创建目录,上传包 创建项目目录 $ mkdir apache_php $ cd apache_php 把包下载后放到服务器该目录下 $ ls apr-....tar.gz 2.创建Dockerfi ...

  9. asp.net MVC项目,localhost响应时间过长

    1.早上高高兴兴的吃完早餐,敲了几句代码,准备调试,竟然发现VS调试项目打开的很慢,最后报错如下图 2.那就很可能是IIS问题嘛,IIS重启了一下,还是不行,在地址栏输入localhost,如下图(本 ...

  10. centos8 安装vmware需要的内核头文件 kernel-headers.

    centos8 安装vmware需要的内核头文件 kernel-headers. uname -r (查看内核版本) rpm -qa kernel-headers (查看kernel-headers版 ...