Hdu2159 two-dimensional backpack

Source: Internet
Author: User

Link: Fate

State transition equation:

DP [Ren] [num] = max (DP [Ren-durable value] [num-1] + experience value, DP [Ren] [num])

DP:Experience of killing the number of enemies under the current endurance Ren


Enumerate all types of monsters, durability, and number of monsters

Finally, the duration consumed by enumeration can be increased from small to small.

# Include <iostream> # include <algorithm> # include <cstdio> # include <cstring> # include <cstdlib> const int INF = 1e7; using namespace STD; int DP [105] [105], cost [600] [2]; int max (int x, int y) {If (x> Y) return X; else return y;} int min (int x, int y) {If (x> Y) return y; else return X;} int main () {int n, m, k, s; while (~ Scanf ("% d", & N, & M, & K, & S) {for (INT I = 1; I <= K; I ++) {scanf ("% d", & cost [I] [0], & cost [I] [1]);} memset (DP, 0, sizeof (DP); int I, Ren, num, ANS =-1; for (I = 1; I <= K; I ++) {for (REN = cost [I] [1]; ren <= m; ren ++) {for (num = 1; num <= s; num ++) {If (DP [Ren] [num] <DP [Ren-cost [I] [1] [num-1] + cost [I] [0]) DP [Ren] [num] = DP [Ren-cost [I] [1] [num-1] + cost [I] [0] ;}} for (INT I = 1; I <= m; I ++) {If (DP [I] [s]> = N) {ans = m-I; printf ("% d \ n", ANS); break ;}} if (ANS =-1) printf ("% d \ n", ANS );} return 0 ;}


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.