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背包,可以把幽 ...
随机推荐
- 10、TestNG 的 FixTrue用法一
Fixture 是指一个测试运行所需的固定环境,通俗来说 ,为测试用例所准备的环境. 以下是TestNG中可用的注释及其属性的简要概述. 我们先演示@BeforeClass.@AfterClass.@ ...
- Linux上调试python程序
python -m pdb target.py
- Day 19:面向对象【类方法】静态属性/静态属性/类方法
静态属性 @property class Mom: gender = "woman" def __init__(self,name,weight): self.name = n ...
- testNG官方文档翻译-1 简介
官方文档链接http://testng.org/doc/documentation-main.html 简介 TestNG是一个被设计用来简化广泛的测试需求的测试框架,它既可应用于单元测试(测试一个独 ...
- 8-MySQL-Ubuntu-数据表中数据的增加(一)
增(insert) (1)全部字段插入数据:按表中字段顺序增加数据 注:(1)主键字段可以使用0/null/default来占位.(2)gender字段中数据类型是枚举,可以使用索引数字1,2,3,4 ...
- webpack 配置之入门二(css 篇)
在项目中我们通过 css 来美化页面,css 也成为了网站不可或缺的一部分,这章节主要介绍 webpack 处理 css 部分, 1.webpack 处理 css 在 webpack 中,我们通过 s ...
- RTL_PROCESS_MODULE_INFORMATION
typedef struct _RTL_PROCESS_MODULE_INFORMATION { HANDLE Section; // Not filled in PVOID MappedBase; ...
- web 服务中上传文件大小控制
参考文章:https://rensanning.iteye.com/blog/2388353 项目场景: Vue + Nginx + Java + Tomcat Nginx作为反向代理服务器,访问To ...
- 2019-4-26-VisualStudio-开发文件自定义工具单文件生成工具
title author date CreateTime categories VisualStudio 开发文件自定义工具单文件生成工具 lindexi 2019-04-26 10:49:32 +0 ...
- umount - 卸载文件系统
总览 umount [-hV] umount -a [-nrv] [-t vfstype] umount [-nrv] device | dir [...] 描述 umount 可以卸除当前挂载在文件 ...