Islands Stone legend <DP>

Source: Internet
Author: User

Islands recently in the end of a game "furnace Stone legend", also known as "Heroes of Warcraft biography." Furnace stone Legend is a card-like game. The game is 2 people to fight, in general, the cards are divided into 2 categories, one is the Magic card , the other is the Entourage card (so-called Entourage is a monster).

to simplify the problem, now assume that the follower cardthe role isSummon one withmust beMonsters of Attack,the function of a spell card is to add to a followermust beattack. Entourage cards and Spell cardsthe Useall Needconsumptiona certain amount of mana. Now Islands has 10 mana, there are n cards on hand (islands up to 10 cards, no one will be a flopt_t), some are spell cards, some are Entourage cards. Islands is now a big disadvantage, and he wants to use the 10 mana to make the attack of all the minions summoned.sumMaximum (mana can not be completed). Note that any spell card must be used in aa summoned Entourage.on, that is, ifIslandsdid not summon the attendants,He willcannot use any spellsCard. Tell Islands heThe total of the attendant who can summonAttackThe maximum is how much.

First enter the number of test data groups T (t<=10) Each set of data first enter an n (0<=n<=10), indicating that islands has n cards next n lines enter 3 integers per line of cost (0<=cost<=10), D (0 or 1), W (| w|<=1000). Cost indicates the mana consumption of the card, if d=0, indicates that the card is a companion card with a damage of W, if d=1, it is a spell card that can add a W attack to a companion.
For each set of data output, output a line in the format "case #x: A" (excluding colons). where x represents the x group of test data and a represents the corresponding answer.
This problem can be simplified into a 01 knapsack question if you do not divide the magic card and the Entourage card, but ... So you have to separate the followers and the Magic cards dp[maxn][2]. dp[capacity][0]: Spell card.
dp[capacity][1]: Entourage card. Note the initialization time. Finally run the 01 backpack on it. The Code of the study of the Great God
#include <iostream> #include <cstdio> #include <algorithm>using namespace std;const int inf=100000;    int Cast[15],d[15],w[15],dp[15][2];int Main () {int t,k=0;scanf ("%d", &t);        while (t--) {int n;scanf ("%d", &n);        for (int i=1;i<=n;i++) scanf ("%d%d%d", &cast[i],&d[i],&w[i]);            for (int i=0;i<=10;i++) {dp[i][1]=-inf;        dp[i][0]=0;                    } for (int i=1;i<=n;i++) {for (int j=10;j>=cast[i];j--) {if (D[i]) {                    Dp[j][1]=max (dp[j-cast[i]][1]+w[i],dp[j][1]);                                    Dp[j][0]=max (Dp[j-cast[i]][0]+w[i],dp[j][0]);                            } else Dp[j][1]=max (Max (dp[j-cast[i]][1],dp[j-cast[i]][0]) +w[i],dp[j][1]);        }} int ans=0;        for (int i=10;i>=0;i--) Ans=max (ans,dp[i][1]);    printf ("Case #%d:%d\n", ++k,ans); } return 0;}


Islands Stone legend <DP>

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.