poj 1946 Cow Cycling DP
来源:互联网 发布:网络开发包括哪些 编辑:程序博客网 时间:2024/04/29 11:58
dp【n】【e】【d】 表示还有n头奶牛,能量为e,跑d圈所需的最短时间
这里只说一下 n > 1的情况
dp【n】【e】【d】 = min( dp【n-1】【e-p】【d-p】 +dp【1】【e】【p】 )
为什么是这样呢?
因为n头奶牛跑d圈,相当于1头奶牛跑了p圈,剩余n-1头跑了d-p圈(注意一点,不管领头的怎么跑,只要跑了p圈,后面的一定是消耗p点能量,所以时间每次与最前面的一头有关)
要注意,这里是根据d来枚举决策,而不是根据e。。。。
我一开始想根据e来决策,想了好久感觉dp维度太多了。。。。。
AC代码如下:
#include <iostream>#include <cstring>#include <algorithm>#include <cstdio>using namespace std;#define MAX 0x3f3f3f3fint dp[22][110][110];int N, E, D;int DFS( int n, int e, int d ){ if( dp[n][e][d] != -1 ){ return dp[n][e][d]; } if( d == 0 ){ return 0; } if( e < d || e == 0 ){ return MAX; } dp[n][e][d] = MAX; if( n == 1 ){ for( int i = 1; i * i <= e && i <= d ; i++ ){ dp[n][e][d] = min( dp[n][e][d], DFS( n, e - i * i, d - i ) + 1 ); } }else{ for( int i = 1; i <= d; i++ ){ dp[n][e][d] = min( dp[n][e][d], DFS( n - 1, e - i, d - i ) + DFS( 1, e, i ) ); } } return dp[n][e][d];}int main(){ while( scanf( "%d%d%d", &N, &E, &D ) != EOF ){ memset( dp, -1, sizeof( dp ) ); int ans = DFS( N, E, D ); if( ans >= MAX ){ cout << 0 << endl; }else{ cout << ans << endl; } } 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】
- http://www.waitalone.cn/wamp-win764-can-t-loaded-php_curl-solution.html
- 夜尽天明,阳光照不到心
- ZOJ 2278 Fight for Food(LIS)
- SpringMVC访问静态资源
- android高分段进阶攻略(9)——ViewPager补间动画实现京东广告Banner
- poj 1946 Cow Cycling DP
- Seo优化的方方面面你都做到了吗
- 工具abator
- [java-ml 学习笔记(一)] Start
- MSSQL2005/2008怎样生成sql脚本来发布到新环境中
- Comparator和Comparable的区别
- Windows系统极限-程序可使用资源的限制
- web app开发利器 - iscroll4 解决方案
- eclipse插件安装的四种方法