POJ - 2385 Apple Catching(动态规划)
来源:互联网 发布:javier colon知乎 编辑:程序博客网 时间:2024/05/17 23:08
题目连接
初学DP,虽然都是简单的DP,但每做出一道题都不容易啊,不能仅仅局限于一题,更重要的是要触类旁通。
dp[i+1][j] = max(dp[i][j], dp[i][j-1]) + ( t==(j%2+1) ? 1:0);
表示前i个苹果,走j次的最大获得值。可以压缩空间用一维数组即可。
其中( t==(j%2+1) ? 1:0)表示:若已停留在该树,则+1;
#include <iostream>#include <cstdio>using namespace std;const int MAX_T = 1001, MAX_W = 31;int T, W;int dp[MAX_W];inline int cnt(int t, int j) { return t == (j%2+1) ? 1 : 0;}int main(){//freopen("in.txt", "r", stdin);scanf("%d%d", &T, &W);for(int i = 0; i < T; i++){int t;scanf("%d", &t);for(int j = W; j >= 0; j--)if(j == 0)dp[j] += cnt(t, j);elsedp[j] = max(dp[j-1], dp[j]) + cnt(t, j);}int Max = -1;for(int j = 0; j <= W; j++) Max = max(Max, dp[j]);printf("%d\n", Max);return 0;}
0 0
- POJ - 2385 Apple Catching(动态规划)
- poj 2385 Apple Catching(动态规划)
- POJ 2385 Apple Catching 动态规划
- poj Apple Catching(动态规划)
- pku2385 Apple Catching (动态规划)
- POJ2385 Apple Catching 动态规划
- 【动态规划】poj2385 Apple Catching
- POJ 2385 Apple Catching
- POJ-2385-Apple Catching
- poj 2385 Apple Catching
- POJ 2385 Apple Catching
- poj 2385 Apple Catching
- POJ 2385 Apple Catching
- Apple Catching.(POJ-2385)
- poj 2385 Apple Catching
- poj 2385 Apple Catching
- POJ 2385Apple Catching
- poj 2385 Apple Catching
- Visual Studio 跨平台开发实战(2) - Xamarin.iOS 基本控制项介绍
- 练级
- visual assist x key(破解方法及注册机程序下载地址)
- 回归分析(regression analysis)
- 向CSS进军!
- POJ - 2385 Apple Catching(动态规划)
- 刚写完实现更新全部新闻列表的意大利式代码(最后连我都不认得了)
- usaco training 4.4.2 Pollutant Control 追查坏牛奶 题解
- 小学生和大学生谈(±10)%(±3)
- Java并发编程
- 【转】CentOS安装VMware Tools
- 电商派争夺零售派:传统百货扎堆试水O2O
- memcached简介及java使用方法
- YII学习