BZOJ1739: [Usaco2005 mar]Space Elevator 太空电梯

n<=400个东西,每个东西有高度<=100,这种东西在堆放过程中不得超过的最大高度<=40000,以及每个东西的个数<=10,求最高能堆多高。

算了下背包复杂度不太对然后开了bitset。。

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<stdlib.h>
 4 #include<algorithm>
 5 #include<bitset>
 6 //#include<iostream>
 7 using namespace std;
 8 
 9 int n;
10 #define maxn 411
11 struct Obj{int h,m,c;}a[maxn];
12 bool cmp(const Obj &a,const Obj &b) {return a.m<b.m;}
13 bitset<40011> f,tmp,t;
14 int main()
15 {
16     scanf("%d",&n);
17     for (int i=1;i<=n;i++) scanf("%d%d%d",&a[i].h,&a[i].m,&a[i].c);
18     f.reset();f[0]=1;
19     tmp.set();
20     sort(a+1,a+1+n,cmp);
21     for (int i=1;i<=n;i++)
22     {
23         for (int j=1;j<=a[i].c;j++)
24             f|=(f<<a[i].h);
25         t=tmp<<(a[i].m+1);t.flip();
26         f&=t;
27     }
28     int ans;
29     for (ans=40000;ans;ans--) if (f[ans]) break;
30     printf("%d\n",ans);
31     return 0;
32 }
View Code

 

posted @ 2017-09-19 19:14  Blue233333  阅读(489)  评论(0编辑  收藏  举报