Battle Ships is a new game which was similar to Star Craft. In this game, the enemy builds a defense tower, which have L longevity. The player has a military factory, which can produce N kinds of battle ships. The factory takes seconds to produce the-th battle ship and this battle ship can make the ti i tower loss li Lon Gevity every second when it had 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 does 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 should spend to win the game.
Input
There is multiple test cases.
The first line of all case contains-integers N (1≤ N ≤30) L and (1≤ L ≤330), is the number of N The kinds of Battle Ships, is the longevity of the L Defense Tower. Then the following N lines, each line contains the integers t i (1≤ ≤20 t i ) and li (1≤ ≤330 li ) Indicati Ng 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 should spend to win the game.
Sample Input
1 11 12 101 12 53 1001 103 2010 100
Sample Output
245
This problem is more difficult to think of, after reading the puzzle after the sudden epiphany. This time as a capacity, the monster's blood for the value, using DP[J] to show that J can hit the maximum amount of monster blood, then use a complete backpack can be Dp[j]=max (dp[j],dp[j-t[i]]+ (J-t[i]) *l[i]), wherein Dp[j-t[i]] It is because of the beginning of the production to spend t[i] time, the back refers to the production of every second after the amount of blood can be beaten.
#include <stdio.h> #include <string.h>int max (int a,int b) {return a>b?a:b;} int Dp[500];int Main () {int N,m=490,last,i,j;int t[50],l[50];while (scanf ("%d%d", &n,&last)!=eof) {for (i=1;i <=n;i++) {scanf ("%d%d", &t[i],&l[i]);} Memset (Dp,0,sizeof (DP)); for (i=1;i<=n;i++) {for (j=t[i];j<=m;j++) {Dp[j]=max (dp[j],dp[j-t[i]]+ (J-t[i]) *l[i]) ;}} for (i=1;i<=m;i++) {if (dp[i]>=last) {printf ("%d\n", I); return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
zoj3623 Battle Ships