[DP] HDU 2660 accepted neck133 limits backpack

Source: Internet
Author: User

The total weight of up to k items selected for N items cannot exceed W

Because each item has only one transfer order

For (INT I = 0; I <n; I ++)
For (Int J = W; j> = B [I]; j --)
For (int l = 1; L <= K; l ++)

Ensures that only one item is placed once.

# Include <stdio. h> # include <string. h> # include <stdlib. h> # include <string> # include <iostream> # include <algorithm> # include <sstream> # include <math. h> using namespace STD; # include <queue> # include <stack> # include <vector> # include <deque> # include <set> # include <map> # define CLer (ARR, Val) memset (ARR, Val, sizeof (ARR) # define in freopen ("in.txt", "r", stdin); # define out freopen ("out.txt", "W ", stdout); typedef long ll; const int maxn = 1000006; // maximum number of points const int maxm = 20006; // maximum number of sides const int INF = 1101521204; const int mod = 1000000007; int DP [23] [1211], a [1111], B [1111]; int main () {int N, T, M, K, w; // In; scanf ("% d", & T); While (t --) {CLer (DP, 0); scanf ("% d ", & N, & K); For (INT I = 0; I <n; I ++) scanf ("% d", & A [I], & B [I]); scanf ("% d", & W); For (INT I = 0; I <n; I ++) for (Int J = W; j> = B [I]; j --) for (INT L = 1; L <= K; l ++) DP [l] [J] = max (DP L-1] [J-B [I] + A [I], DP [l] [J]); printf ("% d \ n", DP [k] [W]);}


[DP] HDU 2660 accepted neck133 limits backpack

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.