POJ3292 SpaceElevator [DP]

Source: Internet
Author: User

A cow is going to go to space. He has many kinds of stones. The height of each kind of stone is hi, but it cannot be placed on the height of ai, and this kind of stone has ci
Combine these stones and ask the highest possible height.
Solution: first, Sort data in ascending order, which is a standard problem of multiple backpacks.
Why sort?
Because only in this way can we get the optimal solution. If it is higher at the beginning, there will be lower but not higher options at the end, so we can directly choose higher ones. In this way, the optimal solution cannot be achieved.
Indicates whether the State mark of f [I] can reach this height.
In this way, the maximum I value in f [I] can be obtained.

Note that when assigning an initial value to max, the value must be 0, not-1, because the answer may be 0.

#include <iostream>#include <cmath>#include <cstring>#include <cstdio>#include <cstdlib>#include <algorithm>using namespace std;int type;int f[44444],usr[44444];struct Block{int h,a,c;}block[555];bool cmp(Block a,Block b){return a.a<b.a;}int main(){scanf("%d",&type);for(int i=1;i<=type;i++){scanf("%d%d%d",&block[i].h,&block[i].a,&block[i].c);}sort(block+1,block+1+type,cmp);int maxn=0;f[0]=1;for(int t=1;t<=type;t++){memset(usr,0,sizeof(usr));for(int h=block[t].h;h<=block[t].a;h++){if(!f[h] && f[h-block[t].h] && usr[h-block[t].h]+1<=block[t].c){usr[h]=usr[h-block[t].h]+1;f[h]=1;maxn=max(h,maxn);}}}printf("%d\n",maxn);return 0;}


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.