2068Magic Tree

2068   Magic Tree

题目描述

Every acmer dream for gold medal. Fotunately,there are two magic trees (which are conveniently numbered 1 and 2) in our campus, each full of gold medal. The trees are very high, so we can not touch the gold medal when they are in the tree but wait for them to fall. However, we must catch them in the air since the gold medal disappear when they hit the ground.

    Each minute, one of the two magic trees drops a medal. we can catch an medal if we are standing under a tree from which one falls. The magic tree 1 is near by the magic tree 2.So we can walk between the two trees quickly (in much less than a minute), we can stand under only one tree at any time. Moreover, we are not willing to walk back and forth between the trees endlessly (and thus misses some gold medal). 

    Medal fall (one each minute) for T (1 ≤ T ≤ 1,000) minutes. We are willing to walk back and forth at most W (1 ≤ W ≤ 30) times. Given which tree will drop an medal each minute, determine the maximum number of medal which we can catch. We starts at magic tree 1.

输入格式:

Line 1: Two space separated integers: T and W 
Lines 2~T+1: 1 or 2, the tree that will drop a medal each minute.

输出格式:

Line 1: The maximum number of medal we can catch without running more than W times.

输入样例 复制
7 2
2
1
1
2
2
1
1
输出样例 复制
6

说明

INPUT DETAILS: 
       Seven medal 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.We are willing to walk from one tree to the other twice. 

OUTPUT DETAILS: 
       We can catch six medals 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.

2
2
通过提交
时空限制1000ms/128mb
题目来源
评测方式在线评测
题目类型
难        度