POJ Dynamic planning DP-2392 Space Elevator

Source: Internet
Author: User

Backpack nine talk about the multi-knapsack problem inside. Each block has a height and quantity, and there is a maximum height to the position limit. We first have to sort the height limit before DP, because from the intuitive point of view, we also need to deal with the smaller blocks that can reach the height, so that we can get the maximum value. For example the first height is 11, the limit height is 100, the second limit height is 10, that if processed directly, the second one will not be processed to.

#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX (x, y) (x>y?x:y) struct block{ int h;int a;int c;}; struct block Data[410];int  dp[40010]={0};int cmp (const void*p1,const VOID*P2) {return (* (block*) p1). a > (* (Block *) p2). A?1:-1;} int main () {int k,i,j,m;scanf ("%d", &k); for (i=0;i<k;i++) {scanf ("%d%d%d",&data[i].h,&data[i].a,& DATA[I].C);} Qsort (Data,k,sizeof (data[0]), CMP), memset (Dp,0,sizeof (DP)); for (i=0;i<k;i++) {for (m=1;m<=data[i].c;m++) for ( j=data[i].a;j>=data[i].h;j--) Dp[j]=max (dp[j],dp[j-data[i].h]+data[i].h);} int ans=0;for (i=0;i<=data[k-1].a;i++) Ans=max (Ans,dp[i]);p rintf ("%d\n", ans); return 0;}



POJ Dynamic planning DP-2392 Space Elevator

Related Article

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.