#1750. [Usaco2005 qua] Apple Catching

[Usaco2005 qua] Apple Catching

题目描述

It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 11 and 22) 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 TT minutes. Bessie is willing to walk back and forth at most WW times.

Given which tree will drop an apple each minute, determine the maximum number of apples which Bessie can catch. Bessie starts at tree 11.

输入格式

  • Line 11:Two space separated integers:TT and WW.
  • Lines 2T+12 \sim T + 111 or 22:the tree that will drop an apple each minute.

输出格式

  • Line 11: The maximum number of apples Bessie can catch without walking more than WW times.
7 2
2
1
1
2
2
1
1
6

样例说明

Seven apples fall - one from tree 22, then two in a row from tree 11, then two in a row from tree 22, then two in a row from tree 11.

Bessie is willing to walk from one tree to the other twice. Bessie can catch six apples by staying under tree 11 until the first two have dropped, then moving to tree 22 for the next two, then returning back to tree 11 for the final two.

数据规模与约定

对于 100%100\% 的数据:1T1031 \leq T \leq 10^31W301 \leq W \leq 30

题目来源

Usaco2005 qua