当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
![P5733 [deep foundation 6. example 1] automatic correction](/img/34/081dbd805593a92a86c3081d6772e3.png)
P5733 [deep foundation 6. example 1] automatic correction

Appearance mode (facade)

National standard gb28181 protocol easygbs cascaded universal vision platform, how to deal with live message 403?

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

Detailed explanation of C const: definition and use of C constant

Verilog中的系统任务(显示/打印类)--$display, $write,$strobe,$monitor

Word文档导出(使用固定模板)

First knowledge - Software Testing

P2393 yyy loves Maths II

Software testing - concept
随机推荐
Is it safe for the head teacher to open a stock account and open an account for financial management?
HDU 5860
Software testing - concept
postgis计算角度
倍福将EtherCAT模块分到多个同步单元运行--Sync Units的使用
【网络是怎么连接的】第二章(中):一个网络包的发出
Analysis and protection of heart blood dripping vulnerability (cve-2014-0160)
Electron official docs series: Get Started
Do you know the limitations of automated testing?
Appearance mode (facade)
使用SSH密钥对登陆服务器
Electron official docs series: References
UVa11582 [快速幂]Colossal Fibonacci Numbers!
Don't mess with full_ Case and parallel_ CASE
Digital signal processing -- Design of linear phase type (Ⅰ, Ⅲ) FIR filter (1)
This function has none of deterministic, no SQL solution
P2393 yyy loves Maths II
【网络是怎么连接的】第二章(上): 建立连接,传输数据,断开连接
倍福PLC旋切基本原理和应用例程
HDU1724[辛普森公式求积分]Ellipse