Battle Ships Time limit: 2 Seconds Memory Limit: 65536 KB
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 Long Evity 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 ) 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 should spend to win the game.
Sample Input
1 11 12 101 12 53 1001 103 2010 100
Sample Output
245
Test instructions: There are n kinds of ships give the time to make each kind of ship and the boat can hit how many drops of blood a second, give the total blood volume, ask how many seconds to hit L drop blood.
Set Dp[i] represents the maximum number of drops of blood that can be knocked out in the second. The answer is to enumerate from the No. 0 second to find the first one that is greater than or equal to L.
Dp[j+t[i]] = max{Dp[i+t[i]], dp[j] + l[i]*j}
#include <algorithm> #include <cstdio> #include <vector> #include <cmath> #include <queue > #include <set> #include <map> #include <cstring> #include <cstdlib> #include <iostream >//#include <bits/stdc++.h> #define MAX 0x3f3f3f3f#define N 100005#define M 200005#define mod 1000000007#define Lson o<<1, L, M#define Rson o<<1|1, m+1, rtypedef Long long ll;using namespace std;const double pi = acos (-1.0 int n, M;int t[40], l[40], Dp[40000];int main () {//freopen ("In.txt", "R", stdin); while (~SCANF ("%d%d", &n, &m)) {for (int i = 0; i < n; i++) {scanf ("%d%d", &t[i], &l[ I]); } memset (DP, 0, sizeof (DP)); for (int i = 0, i < n; i++) {for (int j = 0; J <= 340; j + +) {dp[t[i] + j] = max (dp[t[i] + j], Dp[j] + j*l[i]); }} for (int i = 0; i < i++) {if (Dp[i] >= m) {printf ("%d\n", i); Break }}}return 0;}
ZOJ3623 Battle Ships (full backpack)