题目链接

题意

一共有两个苹果树,每个树会落下苹果,一共会掉下T个苹果,Bessie最初在第一棵树,一共可以移动W次,最多可以接到几个苹果

AC

  • dp
    dp[ i ][ j ]表示第 i 个苹果在移动 j 次可以接到苹果的最大值
    dp[ i ][ j ] = max ( dp[ i - 1][ j ], dp[ i - 1][ j - 1 ] ) + 1 ?
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <map>
#include <bitset>
#include <string.h>
#include <cmath>
#include <algorithm>
#define N 1000015
#define P pair<int,int>
#define ll long long
#define mk(a, b) make_pair(a, b)
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
int dp[1003][31];
int main(){
#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);
#endifint t, w;cin >> t >> w;vector<int> a(t + 1);for (int i = 1; i <= t; ++i) {cin >> a[i];}int ans = 0;for (int i = 1; i <= t; ++i) {for (int j = 0; j <= w; ++j) {if (j == 0)     dp[i][j] = dp[i - 1][j];elsedp[i][j] = max(dp[i - 1][j], dp[i - 1][j - 1]);if ((j % 2 && a[i] == 2) || (j % 2 == 0 && a[i] == 1))  dp[i][j]++;ans = max(ans, dp[i][j]);}}cout << ans << endl;return 0;
}

POJ 2385 Apple Catching相关推荐

  1. POJ - 2385 Apple Catching (dp)

    题意:有两棵树,标号为1和2,在Tmin内,每分钟都会有一个苹果从其中一棵树上落下,问最多移动M次的情况下(该人可瞬间移动),最多能吃到多少苹果.假设该人一开始在标号为1的树下. 分析: 1.dp[x ...

  2. POJ 2385: Apple Catching

    借鉴了别人的思路: 1.dp[i][j] = 第i秒走了移动j次所接到的苹果的数目 2.dp[i][j] = max(dp[i-1][j-1]+dp[i-1][j])+(第i秒接到的苹果数目) #in ...

  3. poj 2382 Apple Catching 入门dp

    点击打开链接 #include <iostream> #include <algorithm> using namespace std; const int M =1010; ...

  4. Apple Catching

    Apple Catching - POJ 2385 - Virtual Judge https://vjudge.net/problem/POJ-2385 题意:有两棵树,每分钟树上会掉下一颗苹果,问 ...

  5. Apple Catching经典dp

    Apple Catching - POJ 2385 - Virtual Judge 状态:第i分钟移动j次能吃多少个苹果 决策:第i分钟动不动 转移:如果移动,dp[i][j]=dp[i-1][j-1 ...

  6. poj 3321 Apple Trie

    /*poj 3321 Apple Trie这道题的关键是如何将一个树建成一个一维数组利用树状数组来解题!可以利用dfs()来搞定,我们在对一个节点深搜后,所经过的节点的数目就是该节点的子树的数目所以我 ...

  7. bzoj 3384: [Usaco2004 Nov]Apple Catching 接苹果(DP)

    3384: [Usaco2004 Nov]Apple Catching 接苹果 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 114  Solved: ...

  8. P2690 [USACO04NOV]Apple Catching G

    P2690 [USACO04NOV]Apple Catching G 题目背景 USACO 题目描述 很少有人知道奶牛爱吃苹果.农夫约翰的农场上有两棵苹果树(编号为1和2), 每一棵树上都长满了苹果. ...

  9. [DP]Apple Catching G

    [DP]Apple Catching G 题面 题目描述 输入格式 输出格式 样例 解析 题面 题目描述 很少有人知道奶牛爱吃苹果.农夫约翰的农场上有两棵苹果树(编号为111和222), 每一棵树上都 ...

最新文章

  1. http权威指南-http连接管理
  2. Eclipse中使用Ctrl键卡顿响应慢的解决方法
  3. 关于Adapter对数据库的查询、删除操作
  4. binlog2mysql,MySQL 数据恢复工具之binlog2sql
  5. java基础----Base64算法的使用
  6. 《机器学习实战》chapter 07利用AdaBoosting元算法提高分类性能
  7. Android Splash闪屏页秒开 Activity白屏、Activity黑屏问题
  8. 因 inode 不足导致数据库登陆报错相关问题
  9. IIS7和IIS8环境下 ThinkPHP专用URL Rewrite伪静态规则
  10. 国际音标的显示和输入
  11. ajax调用一般应用程序,【Web前端】---js调用本地应用程序
  12. 高清优质PPT模板20篇下载(金融投资系列)
  13. 航空机票预定系统软件结构图
  14. 中国未来可能面临的第四次失业浪潮
  15. linux运行getch吗,在linux中使用getch()函数
  16. visual studio和vs code 哪个好用,适用于哪个阶段
  17. sequoia负载均衡
  18. 从库延迟增大,MySQL日志出现InnoDB: page_cleaner: 1000ms intended loop took 17915ms.
  19. 三恒矿用计算机,三恒KJ70N-WG矿用本安型无线网关
  20. 我们是科幻迷(刘慈欣)

热门文章

  1. 仿照微信的效果,实现了一个支持多选、选原图和视频的图片选择器,适配了iOS6-10系统,3行代码即可集成....
  2. 【转载】COM 组件设计与应用(四)——简单调用组件
  3. c++对象的内存布局2--进阶篇---C++ 对象的内存布局(上)
  4. apache下php无法连接mysql问题的解决
  5. document.execCommand()函数可用参数解析 (转)
  6. [网络安全自学篇] 十八.XSS跨站脚本攻击原理及代码攻防演示(一)
  7. C# 系统应用之鼠标模拟技术及自动操作鼠标
  8. 【数据结构与算法】之深入解析“学生出勤记录I”的求解思路与算法示例
  9. 【数据结构与算法】之深入解析“不同路径III”的求解思路与算法示例
  10. OpenGL ES之GLSL实现索引绘制及渲染纹理和颜色混合