Zoj 3623 Battle Ships dp
Zookeeper
Description
Battle ShipsIs a new game which is similarStar Craft. In this game, the enemy builds a defense tower, which hasLLongevity. The player has a military factory, which can produceNKinds of battle ships. The factory takesTiSeconds to produceI-Th battle ship and this battle ship can make the tower lossLiLongevity every second when it has been produced. if the longevity of the tower lower than or equal to 0, the player wins. notice that at each time, the factory can choose only one kind of battle ships to produce or do nothing. and producing more than one battle ships of the same kind is acceptable.
Your job is to find out the minimum time the player shocould spend to win the game.
Input
There are multiple test cases.
The first line of each case contains two integersN(1 ≤N≤ 30) andL(1 ≤L≤ 330 ),NIs the number of the kinds of Battle Ships,LIs the longevity of the Defense Tower. Then the followingNLines, each line contains two integersT I(1 ≤T I≤ 20) andLi(1 ≤Li<330) indicating the produce time and the lethality of the I-th kind Battle Ships.
Output
Output one line for each test case. An integer indicating the minimum time the player shocould spend to win the game.
Sample Input
1 11 12 101 12 53 1001 103 2010 100
Sample Output
245
Question and analysis:
Because you can choose to do or not to do it each time. So of course we chose to build a warship. Dp [j] indicates the damage caused by j within the time. The time before dp [j + t [I] t [I] was used to build warships. The remaining j time can be viewed as a small whole. Dp [j + t [I] = max (dp [j + t [I], dp [j] + j * a [I]); this is the expected recursive formula.
AC code: