Bzoj 3407: [Usaco2009 oct]bessie ' s Weight problem Bessie's weight problem (DP)

Source: Internet
Author: User

01 Backpack ...

-----------------------------------------------------------------------

#include <cstdio>#include <algorithm>#include <cstring>#include <iostream>#define REP (i, n) for (int i = 0; i < n; i++)#define CLR (x, C) memset (x, C, sizeof (x)) using namespace std;const int MAXN = 45000 + 5;bool d[MAXN];int main () {freopen ("test.in", "R", stdin);CLR (d, 0);d[0] = true;int v, n;Cin >> v >> N;Rep (i, N) {int x;scanf ("%d", &x);For (int j = v-x; J >= 0; j--) if (d[j])d[j + x] = true;    }int ans = 0;Rep (i, v + 1) if (d[i])ans = max (ans, i);cout << ans << "\ n";return 0;}

-----------------------------------------------------------------------

3407: [Usaco2009 oct]bessie ' s Weight problem Bessie's weight problem time limit: 3 Sec Memory Limit: MB
Submit: Solved: 50
[Submit] [Status] [Discuss] DescriptionBessie, like many of her sisters, grew too much fat by eating too much delicious grass from John's lawn. So John puts her in a strict diet plan. She can't eat more than H (5≤ day ≤45000) kg of hay every day. Bessie could only eat a whole bundle of hay, and when she began to eat a bundle of hay, she could no longer stop. She has a completethe N (1≤n≤500) bundle can give her a list of hay for supper. She naturally wants to eat as much hay as possible. Naturally, each bundle of hay can only be eaten once (even though the same weight may occur 2 times in the list, this represents two bales of hay, where each bundle of hay can only be eaten once). given a list of the weights of each bundle of hay Si (1≤si≤h), ask Bessie to eat as much hay without exceeding the limits of dieting (note that once she starts eating a bundle of hay, she will eat all that bundle of hay). Inputline 1th: Two integer days and n separated by a space.2nd to N+1: Line i+l is a single integer representing the weight of the bales of hay si. OutputA single integer indicates how many kilograms of hay can be eaten by Bessie within the limits. Sample Input56 4
15
19
20
+Sample Output AboutHINT

There are four bales of grass, with weightsof 21, respectively . Bessie could eat as much as she wanted to eat within the limits of the range of pounds.


Betsy can eat 3 bales of hay (the weight is ,respectively). Just reached her limit of up to a kilo.


Source

Gold

Bzoj 3407: [Usaco2009 oct]bessie ' s Weight problem Bessie's weight problem (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.