POJ- -3628 Bookshelf 2

Source: Internet
Author: User

Title Link: http://poj.org/problem?id=3628

Test instructions

Problem Solving Ideas:

1 determine the maximum possible height sum, which is the height of all the cow added up

2 According to the dynamic programming method, the possible solution between the sum of 1 to the maximum height is solved

3 found the lowest height than B (Bookshelf height), which may be the same as B.

Sample Input 5  - 3 1 3 5 6 Sample Output 1

AC Code:

1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <queue>5#include <algorithm>6#include <cmath>7#include <iostream>8 9 using namespacestd;TentypedefLong LongLL; One  A #defineINF 0x3f3f3f3f - #defineN 1200000 - #defineMAXN 100000000 the #defineMoD 1000000007 -  - intDp[n],a[n]; -  + intMain () - { +     intn,x,sum,i,j; A  at      while(SCANF ("%d%d", &n,&x)! =EOF) -     { -Memset (DP,0,sizeof(DP)); -Memset (A,0,sizeof(a)); -  -sum=0; in          for(i=1; i<=n;i++) -         { toscanf"%d", &a[i]); +sum+=A[i]; -         } the  *          for(i=1; i<=n;i++) $              for(j=sum;j>=a[i];j--)Panax NotoginsengDp[j]=max (dp[j],dp[j-a[i]]+a[i]); -  the          for(i=1; i<=sum;i++) +         { A             if(dp[i]>=x) the             { +printf"%d\n", dp[i]-x); -                  Break; $             } $         } -     } -     return 0; the}

POJ- -3628 Bookshelf 2

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.