POJ_2385_Apple Catching_简单DP
来源:互联网 发布:遥感数据特点 编辑:程序博客网 时间:2024/04/28 05:28
听了一天古典钢琴曲真不错
题意:
农夫约翰又养了一头极吊的牛Bessie,他喜欢吃苹果,有两棵苹果树,从1到T秒,每分钟其中一棵树会掉苹果,Bessie每分钟站在其中一棵树下,如果此时掉苹果,就能吃到,他最多移动W次,移动不算时间,问T分钟后他最多吃到多少个苹果。
Input
* Line 1: Two space separated integers: T(1000) and W(30)
* Lines 2..T+1: 1 or 2: the tree that will drop an apple each minute.
* Lines 2..T+1: 1 or 2: the tree that will drop an apple each minute.
Output
* Line 1: The maximum number of apples Bessie can catch without walking more than W times.
如果用搜索,那么至少有2^w个状态,肯定TLE,动态规划,记录当前时间、当前位置、当前移动次数即可
代码如下:
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>using namespace std;#define mxt 1010#define mxw 40int t,w;int a[mxt];int dp[2][mxt][mxw];int main(){scanf("%d%d",&t,&w);for(int i=1;i<=t;++i)scanf("%d",&a[i]);memset(dp,0,sizeof(dp));int ans=0;for(int j=1;j<=t;++j)for(int i=0;i<2;++i)for(int k=0;k<=min(j-1,w);++k){dp[i][j][k]=dp[i][j-1][k]+(a[j]==i+1 ? 1 : 0);if(k-1>=0)dp[i][j][k]=max(dp[i][j][k],dp[1-i][j-1][k-1]+(a[j]==i+1 ? 1 : 0));ans=max(ans,dp[i][j][k]);}printf("%d\n",ans);return 0;}
0 0
- POJ_2385_Apple Catching_简单DP
- 简单DP
- 简单dp
- 简单dp
- 简单DP
- 简单dp
- 简单DP
- 简单?dp
- 简单dp
- 简单dp
- 简单DP
- 简单DP
- 简单dp
- dp专题2--简单dp
- PKU3356 AGTC (简单DP)
- POJ2192 Zipper(简单DP)
- HDU 1087 简单DP
- zoj 2402 简单dp
- hdu4916 Count on the path,树dp
- 数据结构与算法之模拟算法 C++实现
- javascript制作的时钟
- SAMBA服务器的搭载与win8.1环境下的访问
- Dreamweaver CS6 Mac破解版
- POJ_2385_Apple Catching_简单DP
- 原生Javascript之拖曳效果
- 风宇冲的Logo闪亮(光亮偏移)效果shader
- Sharepoint
- UVA 10954
- uva 11045(二分图匹配)
- UIImageView的讲解
- QT c1803
- CString 转 char *