POJ 1946 Cow Cycling DP
来源:互联网 发布:java中的接口的作用 编辑:程序博客网 时间:2024/04/29 15:25
题目大意:有N只牛,每只牛初始体力E,一共要跑D圈。每次跑的时候,牛群有一个领跑者,它若以 x/圈(x必须是整数) 的速度开始跑,跑完x圈,它将花费x*x的体力,而其他牛将花费x的体力。牛群可以随意切换领跑者,切换时间忽略。奔跑过程中,可以抛弃任何一只牛,领跑者可以随意更换速度。问,至少一只牛跑完D圈的最小时间。
思路:想到,一只牛,如果让它做领跑者,再让它不做领跑者跑一段时间,之后再让它做领跑者。这种情况,可以忽略,因为这种情况,一定不会更优。我们认为,每只牛的命运都是:做领跑者,被抛弃。想到这,这题就好做了。dp[ i ][ j ][ k ]:跑了i圈,牛群还有j只牛,领跑者体力为k。
//#pragma comment(linker, "/STACK:102400000,102400000")#include<cstdio>#include<cstring>#include<vector>#include<queue>#include<cmath>#include<cctype>#include<string>#include<algorithm>#include<iostream>#include<ctime>#include<map>#include<set>using namespace std;#define MP(x,y) make_pair((x),(y))#define PB(x) push_back(x)typedef long long LL;//typedef unsigned __int64 ULL;/* ****************** */const int INF=100011122;const double INFF=1e100;const double eps=1e-8;const LL mod=20120427;const int NN=10;const int MM=1000010;/* ****************** */int dp[105][25][105];int main(){ int N,E,D; int i,j,k,k1,t,ans; while(scanf("%d%d%d",&N,&E,&D)!=EOF) { for(i=0;i<=D;i++) for(j=0;j<=N;j++) for(k=0;k<=E;k++) dp[i][j][k]=INF; dp[0][N][E]=0; for(i=0;i<D;i++) { for(j=1;j<=N;j++) for(k=0;k<=E;k++) if(dp[i][j][k]!=INF) { for(k1=1;k1*k1<=k;k1++) { t=min(i+k1,D); dp[t][j][k-k1*k1]=min(dp[t][j][k-k1*k1],dp[i][j][k]+1); } if(j>=2) { for(k1=1;k1*k1<=E-i;k1++) { t=min(i+k1,D); dp[t][j-1][E-i-k1*k1]=min(dp[t][j-1][E-i-k1*k1],dp[i][j][k]+1); } } } } ans=INF; for(j=1;j<=N;j++) for(k=0;k<=E;k++) ans=min(ans,dp[D][j][k]); printf("%d\n",ans); } return 0;}
0 0
- poj 1946 Cow Cycling DP
- POJ-1946 Cow Cycling DP
- POJ 1946 Cow Cycling DP
- POJ 1946 Cow Cycling
- poj 1946 Cow Cycling
- POJ 1946 Cow Cycling
- poj 1946 Cow Cycling
- poj 1946 Cow Cycling
- POJ 1946 Cow Cycling
- POJ 1946 Cow Cycling
- pku 1946 Cow Cycling(DP)
- poj 1946 Cow Cycling 动态规划
- POJ [USACO] Cow Cycling
- POJ1946 Cow Cycling
- POJ 3176 Cow Bowling DP
- poj-3176-Cow Bowling-dp
- poj 3176 Cow Bowling (DP)
- poj 3167 Cow Bowling【dp】
- How do I use the locate command within a specified directory?
- [C#] VS2012连接SQL Server2012数据库的连接方式
- HDU1022--火车进出站问题Ⅰ
- C#元祖Tuple的事例
- B - Ugly Numbers(1.5.8)
- POJ 1946 Cow Cycling DP
- 字符串的基本知识点
- 题目一
- 滚动数组的应用
- MyEclipse 显示内存使用状态
- Lua中的字符串函数库
- 【鸟哥Linux学习笔记】关于Linux磁盘管理和文件系统(1)
- ThinkPHP 项目笔记
- CentOS7下源码安装Apache2.4.9