当前位置:网站首页>E - Apple Catching
E - Apple Catching
2022-06-26 13:09:00 【YJEthan】
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
* Lines 2..T+1: 1 or 2: the tree that will drop an apple each minute.
Output
Sample Input
7 2 2 1 1 2 2 1 1
Sample Output
6
Hint
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.
The general meaning of the topic is : There is a cow , There are two magic apple trees , Two apple trees fall apples every second , At first the cows were 1 Under the tree , Cows move at most m Next , Ask how many apples the cow can eat at most
j%2+1 Indicates the location of the current cow
dp[I][j] Before presentation I Second move j How many apples did the cow eat at most
If a[I]==j%2+1 dp[I][j]=max(dp[I-1][j-1],dp[I-1][j])+1
If a[I]!=j%2+1 dp[I][j]=max(dp[I-1][j-1],dp[I-1][j])
#include<stdio.h>
#include<string.h>
int max(int a,int b)
{
if(a>b) b=a;
return b;
}
int main()
{
int i,j,t,w;
int dp[1005][33];
int a[1005];
while(scanf("%d%d",&t,&w)!=EOF)
{
for(i=1;i<=t;i++)
{
scanf("%d",&a[i]);
}
memset(dp,0,sizeof(dp));
for(i=1;i<=t;i++)
{
dp[i][0]=dp[i-1][0];
if(a[i]==1) dp[i][0]++;
for(j=1;j<=w&&j<=i;j++)
{
if(a[i]==j%2+1)
{
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 max0=dp[t][0];
for(i=1;i<=w;i++)
{
max0=max(max0,dp[t][i]);
}
printf("%d\n",max0);
}return 0;
}
边栏推荐
- Electron official docs series: References
- Record a phpcms9.6.3 vulnerability to use the getshell to the intranet domain control
- LeetCode_栈_中等_150. 逆波兰表达式求值
- 桥接模式(Bridge)
- Solution of Splunk iowait alarm
- processing 函数translate(mouseX, mouseY)学习
- Electron official docs series: Examples
- P5733 【深基6.例1】自动修正
- PostGIS calculation angle
- Electron official docs series: Processes in Electron
猜你喜欢

Solution of Splunk iowait alarm

C# const详解:C#常量的定义和使用

组合模式(Composite )

Use the script to crawl the beautiful sentences of the sentence fan website and store them locally (blessed are those who like to excerpt!)

Design of four kinds of linear phase FIR filters -- complete set of Matlab source code

Processsing function random

How does easygbs solve the abnormal use of intercom function?

【网络是怎么连接的】第二章(中):一个网络包的发出

National standard gb28181 protocol easygbs cascaded universal vision platform, how to deal with live message 403?
![[esp32-c3][rt-thread] run RT-Thread BSP minimum system based on esp32c3](/img/4a/503240b332e3279047c438f1d9845e.png)
[esp32-c3][rt-thread] run RT-Thread BSP minimum system based on esp32c3
随机推荐
Mode pont
橋接模式(Bridge)
Processsing function random
[BSidesCF 2019]Kookie 1
Is it safe for the head teacher to open a stock account and open an account for financial management?
Electron official docs series: Development
processing 随机生成线动画
Deeply analyze the differences between dangbei box B3, Tencent Aurora 5S and Xiaomi box 4S
QT . Establishment and use of pri
mariadb学习笔记
黑马笔记---常用API
Learning Processing Zoog
Machine learning notes - seasonality of time series
Processsing mouse interactive learning
Processing random generation line animation
Power Designer - Custom Comment button
Software testing - concept
. Net Maui performance improvement
倍福PLC通过程序获取系统时间、本地时间、当前时区以及系统时间时区转换
PostGIS calculation angle