ZOJ3623: Battle Ships (full backpack), zoj3623ships
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:
The other party has 1 million drops of blood. We have n kinds of ships to choose from. Each type of ship is built at t, which causes 1 point of damage to the enemy every second after construction, and asks the minimum time to kill the other party.
Ideas:
Carry out a backpack with time as the capacity
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;#define inf 1<<30int dp[10000],t[100],l[100];int main(){ int n,m,i,j,sum = 6600,ans; while(~scanf("%d%d",&n,&m)) { for(i = 0; i<n; i++) scanf("%d%d",&t[i],&l[i]); memset(dp,0,sizeof(dp)); for(j = 0; j<333; j++) { for(i = 0; i<n; i++) { dp[j+t[i]] = max(dp[j+t[i]],dp[j]+j*l[i]); } } ans = inf; for(i = 0; i<333; i++) { if(dp[i]>=m) { ans=min(ans,i); } } printf("%d\n",ans); } return 0;}