POJ 2385 Apple Catching(DP)

YOLOv8【第十一章:视频追踪与流处理篇·第6节】BoT-SORT 改进:结合相机运动补偿(CMC)提升追踪稳定性! 🏆 本文收录于 《YOLOv8实战:从入门到深度优化》 专栏。该专栏系统复现并梳理全网各类 YOLOv8 改进与实战案例(当前已覆盖分类 / 检测 / 分割 / 追踪 / 关键点 / OBB 检测等方向),坚持持续更新 + 深度解析,质量分长期稳定在 97 分以上,可视为当前市面上 覆盖较全、更新较快、实战导向极强 的 YOLO 改进系列内容之一。 阅读详情
Apple Catching Time Limit:1000MS    Memory Limit:65536KB    64bit IO Format:%lld & %llu

Description

It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, each full of apples. Bessie cannot reach the apples when they are on the tree, so she must wait for them to fall. However, she must catch them in the air since the apples bruise when they hit the ground (and no one wants to eat bruised apples). Bessie is a quick eater, so an apple she does catch is eaten in just a few seconds.

Each minute, one of the two apple trees drops an apple. Bessie, having much practice, can catch an apple if she is standing under a tree from which one falls. While Bessie can walk between the two trees quickly (in much less than a minute), she can stand under only one tree at any time. Moreover, cows do not get a lot of exercise, so she is not willing to walk back and forth between the trees endlessly (and thus misses some apples).

Apples fall (one each minute) for T (1 <= T <= 1,000) minutes. Bessie is willing to walk back and forth at most W (1 <= W <= 30) times. Given which tree will drop an apple each minute, determine the maximum number of apples which Bessie can catch. Bessie starts at tree 1.

Input

* Line 1: Two space separated integers: T and W

* 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.

Sample Input

7 2
2
1
1
2
2
1
1

Sample Output

6

Hint

INPUT DETAILS:

Seven apples fall - one from tree 2, then two in a row from tree 1, then two in a row from tree 2, then two in a row from tree 1. Bessie is willing to walk from one tree to the other twice.

OUTPUT DETAILS:

Bessie can catch six apples by staying under tree 1 until the first two have dropped, then moving to tree 2 for the next two, then returning back to tree 1 for the final two.



用opt[i][j]表示第i分钟走了j次后最多能摘几个苹果

由于只有两棵树,故用j%2+1就能判断此时Bessie在哪棵树下面,省下了一维空间

f[i]表示第i分钟哪颗树掉苹果,若f[i]==j%2+1,则此时可以摘得苹果,opt[i][j]=max(opt[i-1][j],opt[i-1][j-1])+1

否则,此时摘不到苹果,opt[i][j]==max(opt[i-1][j],opt[i-1][j-1])

但对于opt[i][0]要单独考虑,即第i分钟时仍然没移动,在第一棵树下的情况,可由opt[i-1][0]推导


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int dp[1001][31],f[1001];
int main()
{
    int t,w;
    while(~scanf("%d %d",&t,&w))
    {
        for(int i=1;i<=t;i++) scanf("%d",&f[i]);
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=t;i++){
            dp[i][0]=dp[i-1][0];
            if(f[i]==1)
                dp[i][0]++;
            for(int j=1;j<=w&&j<=i;j++){
                if(j%2+1==f[i]){
                    dp[i][j]=max(dp[i-1][j],dp[i-1][j-1])+1;
                }
                else
                    dp[i][j]=max(dp[i-1][j],dp[i-1][j-1]);
            }
        }
        int k=dp[t][0];
        for(int i=1;i<=w;i++)
           k=max(k,dp[t][i]);
        printf("%d\n",k);
    }
    return 0;
}


IEM模型,地表粗糙度模拟 利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟 立即下载

相关推荐

Python实战:高效稳定采集微信视频号评论的API爬虫方案

网络爬虫是数据采集领域的核心技术,其原理是通过程序模拟浏览器行为,向目标服务器发送HTTP请求并解析响应数据,从而自动化获取网页或接口中的信息。这项技术的核心价值在于能够高效、批量化地收集公开数据,为市场分析、舆情监控和竞品研究提供数据基础。在社交媒体分析、电商价格监控等应用场景中,爬虫技术尤为重要。针对微信视频号这类动态加载的复杂应用,传统的GUI自动化工具(如影刀RPA)常面临性能瓶颈和风控挑战。本文聚焦于通过Python实现**无感采集**,直接与后端**API接口**交互,构建稳定高效的评论数据采集

weixin_30899023的博客 328

Apple Catching POJ - 2385(基础的动态规划算法)

题意: 给你两个数字n和m;代表会有n个苹果掉落,m次可以移动的机会;有两棵树,开始你站在树1下面,一分钟只能移动一次,下面的数值代表在哪一颗树下会掉落苹果;问你在可移动的范围内,最多可以接到多少个苹果? 题目: It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, each full of

zeng_jun_yv的博客 264

使用kali对局域网内的主机进行远程控制

输入命令:hydra -l administrator -P/usr/share/woerdlists/rockyou.txt 192.168.100.241 smb -V。账户(adminitrator)密码:123456 【一般账户都是我们知晓了,如果不知道账户进行破解那几乎不太可能,密码如果设置的特别复杂无规律也是特别难破解的】【-r:扫描整个网段 后面就是设置 192.168.241.100/24的网络地址段 为 192.168.241.0/24 0和/24之间不要空格】

2301_77599769的博客 2278

基础动态规划-POJ2385(Apple Catching)

描述 Description It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, each full of apples. Bessie cannot reach the app...

weixiao2015的博客 308

PSF(点扩散函数)与去卷积算法消除图像模糊

本文旨在总结图像处理中使用去卷积的传统方法来进行图像去模糊的相关知识。

m0_53607446的博客 6013

高德地图API如何使用

通过以上步骤,您可以成功接入并使用高德地图API来为您的应用添加丰富的地图功能。

QQ_778132974的博客 4783

POJ2385 Apple Catching 【DP】

Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8018   Accepted: 3922 Description It is a little known fact that cows love apples. Farmer Jo

长风的专栏 2469

华为od 面试八股文_C语言_01_含答案

华为od 面试八股文_C语言_01_含答案

MISAYAONE的博客 3225

poj2385 dp

如题:http://poj.org/problem?id=2385 Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9298   Accepted: 4528 Description It is a little known fact t

zht的专栏 501

VMware ESXi 直通GPU

虚拟机需要独享GPU资源,那么就需要用到DirectPath I/O (直通),ESXi hypervisor 把 GPU 设备直接映射成虚机中的 GPU 设备,供应用使用。注意,内存注意一定要勾选预留,否则开机后报错如下:无法打开虚拟机 win10 的电源。1.ESXi主机,管理,硬件,PCI设备,勾选GPU卡,切换直通,会提示要求重启主机,重启主机之后,该GPU设备直通一栏显示为“活动”。先确认虚拟机是否EFI引导:编辑虚拟机 - 虚拟机选项 - 引导选项 - 固件 - EFI。

liwension的博客 6293

【乐企文件生成工程】关于乐企文件生成工程的详细介绍

发票文件生成方式有两种思路:1、根据已有的OFD模板,动态替换ofd模板内容;之后将ofd转pdf(局限:单行问题不大)详情可以在此处了解2、根据html模板动态占位:该工程就是这种方式 ,目前效果良好,可看下图。拿去即用的源码!无任何保留,当然也并不是所有票种都支持(时间有限、精力有限、已经连着转了,要冒烟了…)

九七的博客 2031

【题解】Apple Catching POJ - 2385 ⭐⭐【dp 奇偶性】

Apple Catching POJ - 2385 有两棵APP树,编号为1,2.每一秒,这两棵APP树中的其中一棵会掉一个APP.每一秒,你可以选择在当前APP树下接APP,或者迅速移动到另外一棵APP树下接APP(移动时间可以忽略不计),但由于却乏锻炼,你最多移动W次.问在T秒内,你最多能收集多少个APP.假设你开始站在1号APP树下. Input 第1行:两个整数T(1 < = T&...

Suprit's blog 1004

【二】MADDPG多智能体算法实现(parl)【追逐游戏复现】

论文全称:Multi-Agent Actor-Critic for Mixed Cooperative-Competitive Environments 论文原文:https://download.youkuaiyun.com/download/sinat_39620217/16203960 论文翻译:https://blog.youkuaiyun.com/qiusuoxiaozi/article/details/79066612 ...

丨汀、的博客 2万+

POJ 2385 Apple Catching(DP)

POJ 2385 Apple Catching 题意: 解题过程: AC代码: POJ 2385 Apple Catching 题目传送门 题意: 一头牛要接苹果,一共有两棵树,牛刚开始在第一棵树下,每次可以在两棵树之间移动,给出你T秒内下落苹果的树的编号(1或2),问你最多移动K次,能够接到最多的苹果是多少。...

dieyi9889的博客 157

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

poj 2385 Apple Catching DP

题目链接:http://poj.org/problem?id=2385 状态定义: dp[i][j] :=前i秒,移动j次接到的最大苹果数量。 状态转移: dp[i][j]=dp[i-1][j]+num[0][i]; (j==0)                    dp[i][j]=max{dp[i-1][j-1],dp[i-1][j]}+num[j%2==1][i]; (1= 这里输

R_xiaozhu_Q的专栏 2138

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

POJ2385Apple Catching【dp】

Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9265   Accepted: 4507 Description It is a little known fact that cows love apples. Farmer John h

走一步再走一步 818

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

[POJ 2385]Apple Catching[DP]

题目链接:[POJ 2385]Apple Catching[DP] 题意分析: 每分钟树1和树2两棵树之中都会有一棵树掉落苹果,现在给出分钟数N和W次转换树次数,其中,1代表当前分钟苹果在树1掉落,2代表苹果在树2掉落,转换树不耗费时间,问:最多能接多少个苹果? 解题思路: 我们设状态,dp[i][j]代表到第i分钟,转换j次,最多可以拿到多少苹果。那么就有dp[i][j] = max(d

闲停 975

POJ - 2385 Apple Catching dp

传送门:POJ2385 题意:有两颗苹果树,每分钟会从其中某一颗苹果树上掉下一个苹果来,初始在1号树下,可以在树间移动而不花费时间,但是最多移动w次,问最多能接到多少个苹果。 思路:很明显的我们可以根据移动次数奇偶判断在哪颗树下,用dp[i]表示移动i次最多能接到多少苹果,然后对每一个掉下来的苹果进行O(w)的状态转移就好了。 代码: #include #include #define l

WA是一笔财富 317

POJ 2385 Apple Catching (dp)

Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8363   Accepted: 4093 Description It is a little known fact that cows love apples. Farmer Jo

TaoSama's Microcosm 622

POJ 2385 Apple Catching DP

有两棵树,一开始站在第一棵树,每秒有苹果从树上掉下(不会同时两棵树都有),你最多移动w次,求t秒后你能得到的最大的苹果数目。

细语呢喃 1258

POJ 2385 Apple Catching (DP)

传送门:POJ 2385

一个写程序的 743

POJ2385 Apple catching(dp)

题意:Farmer John有两颗苹果树,分别编号为1和2,每棵树上都长满了苹果,Bessie无法摘到树上的苹果,所以只能等待苹果掉下来,厉害的是Bessie每次都能在苹果碰到地之前接住苹果,但前提是Bessie必须当前时刻在这颗树的下方,已知每分钟都有一颗树会掉落一个苹果,Bessie初始位置在第1颗树。现给出一个T代表总时间,W代表Bessie可以移动的次数,即从一颗树到另一颗树算移动一次。

Link_Ray的博客 341

poj 2385 Apple Catching 【暴力dp】

Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9790   Accepted: 4763 Description It is a little known fact that cows love apples. Farmer Jo

世界很大 577

POJ 2385 Apple Catching 简单DP

Description It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, each full of apples. Bessie cannot reach the apple...

RPG_Zero的博客 266

poj 2385 Apple Catching dp

http://poj.org/problem?id=2385 题意:有两棵苹果树,每分钟都会有一棵树上会掉下来一个苹果。你必需要站在这棵树下才干接到这棵树掉下来的苹果,你能够在两棵树之间来回走动。并且不花费时间,可是来回走的次数不超过w次。如今告诉你每分钟从哪棵树上会掉下来苹果。问你最多能接着多少个。你的起始位置是在第一棵树下。 思路:用dp[i][j][k]表示第i...

weixin_30448685的博客 115
上一篇: POJ 393 最长上升子序列(vector容器的巧用)
下一篇: POJ 3616 D - Milking Time(DP)
hellohelloC
博客等级 码龄12年 15粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值