zoj3623 Battle Ships

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.