Zoj problem set-2297 pressure Val [Pressure DP]

Source: Internet
Author: User

Title: zoj problem set-2297 interval Val


Question: There are some strange ideas. There are two values: the blood spent by the attacker and the blood that can be increased. Then there is a boss, which can only be beaten after all the moles are killed, if the blood volume is less than 0, it will die, and cannot exceed 100.


Analysis: defined status: DP [st], indicating the blood volume in the St state.

Then transfer:DP [st] = max (DP [st], DP [st &~ (1 <I)] + P [I]. First-P [I]. Second );

Note that initialization must start at the time of initialization; otherwise, errors may occur.

# Include <cstdio> # include <cstring> # include <string> # include <iostream> # include <algorithm> # include <vector> using namespace STD; const long n = 22; const int INF = 0x3f3f3f3f; int DP [1 <n]; pair <int, int> P [N]; int main () {int N, boss; while (~ Scanf ("% d", & N) {n --; For (INT I = 0; I <n; I ++) {int X, Y; scanf ("% d", & X, & Y); P [I] = make_pair (x, y);} scanf ("% d", & boss ); memset (DP, 0, sizeof (DP); int ans = 0; DP [0] = 100; for (int st = 1; ST <(1 <n ); st ++) {DP [st] =-INF; // The for (Int J = 0; j <n; j ++) must be initialized here) if (st & (1 <j) & DP [st &~ (1 <j)]> = P [J]. First) {DP [st] = max (DP [st], DP [st &~ (1 <j)]-P [J]. first + P [J]. second); If (DP [st]> 100) DP [st] = 100 ;}} if (DP [(1 <n)-1]> = boss) puts ("Clear !!! "); Else puts (" try again ");} return 0 ;}


Zoj problem set-2297 pressure Val [Pressure 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.