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]