【动态规划】poj2385 Apple Catching
来源:互联网 发布:男风时尚生活 知乎 编辑:程序博客网 时间:2024/05/03 19:51
传送门:戳我
大致题意:Bessie在两棵树下面接苹果,苹果每分钟从某一棵树上掉下一个。由于Bessie很懒,所以她不想过多移动。给定时间T和Bessie最多移动次数W,求Bessie最多能接多少苹果
思路:显然的,动态规划。另状态f[i][j]表示Bessie在第i分钟,移动j次所获得的最多的苹果数,则有转移方程:f[i][j]=max(f[i-1][j-1],f[i-1][j])+1/0。在转移过程中记录最大值输出即可。
ps:移动j次后所在的树的编号为j%2+1,所以不需要添加一个记录位置的冗余维度。
#include <iostream>#include <cstring>#include <cstdio>using namespace std;int f[1000+10][30+5];int t,w,a[1000+10];int max(int a,int b){ return a>b?a:b;}int main(){ while (scanf("%d%d",&t,&w)!=EOF){ for (int i=1;i<=t;i++){ scanf("%d",a+i); } memset(f,0,sizeof(f)); int Max=0; if (a[1]==1){ f[1][0]=1; f[1][1]=0; } if (a[1]==2){ f[1][0]=0; f[1][1]=1; } for (int i=2;i<=t;i++) for (int j=0;j<=w;j++){ f[i][j]=max(f[i-1][j],f[i-1][j-1]); if (a[i]==j%2+1) f[i][j]++; if (f[i][j]>Max) Max=f[i][j]; } printf("%d\n",Max); } return 0;}
0 1
- POJ2385 Apple Catching 动态规划
- 【动态规划】poj2385 Apple Catching
- POJ2385 Apple Catching——动态规划
- POJ2385——Apple Catching(动态规划)
- poj2385 - Apple Catching
- POJ2385 Apple Catching
- POJ2385 Apple Catching 【DP】
- poj2385 Apple Catching
- POJ2385--Apple Catching
- POJ2385-Apple Catching
- poj2385 Apple Catching
- POJ2385-Apple Catching
- POJ2385 Apple Catching
- poj2385 Apple Catching
- POJ2385 Apple catching(dp)
- pku2385 Apple Catching (动态规划)
- poj Apple Catching(动态规划)
- POJ2385——Apple Catching
- rsync 命令中的路径斜线
- const对象默认为文件的局部变量
- PAT:4-1. 水仙花数(20)
- opencv 读取视频中的每一帧
- 给自己的话
- 【动态规划】poj2385 Apple Catching
- Clustering by fast search and find of density peaks(code & idea)
- 完美解决 Ubuntu 下 Sublime Text 2配置搜狗拼音输入法
- ZOJ-1134
- Alpha、Beta、RC、GA版本的区别
- 将VIM设置成IDE
- 轻松构建Mysql高可用集群系统
- PAT:4-2. 打印九九口诀表(15)
- Codeforces Round #256 (Div. 2) B. Suffix Structures(模拟)