hdu5410--01 backpack + Full backpack--CRB and his Birthday

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=5410

/* First 01 backpacks and then a full backpack *//************************************************* Author:P owatr* Created time:2015-8-20 19:46 : 35* File name:1005_1.cpp ************************************************/#include <cstdio> #include < algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cmath># Include <string> #include <vector> #include <queue> #include <deque> #include <stack># Include <list> #include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime>using namespace std; #define Lson L, Mid, RT << 1#define Rson mid + 1, R, RT << 1 | 1typedef long ll;const int MAXN = 1e5 + 10;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;int A[MAXN], B[MAXN], C    [Maxn];int Dp[maxn];int Main () {int T;    int n, m;    scanf ("%d", &t);        while (t--) {scanf ("%d%d", &m, &n);        memset (DP, 0, sizeof (DP)); for (int i = 1; I <= N        i++) scanf ("%d%d%d", &a[i], &b[i], &c[i]); for (int i = 1; I <= n; i++) {for (int j = m; J >= A[i]; j--) dp[j] = max (Dp[j], dp[j-a[i])            + B[i] + c[i]);        for (int j = a[i]; j <= M; j + +) Dp[j] = max (Dp[j], Dp[j-a[i]] + b[i]);    } printf ("%d\n", Dp[m]); } return 0;}

  

hdu5410--01 backpack + Full backpack--CRB and his Birthday

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.