码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-09-19 19:53:23      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:one   int   col   背包   复杂度   --   view   复杂   ace   

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

 

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

标签:one   int   col   背包   复杂度   --   view   复杂   ace   

原文地址:http://www.cnblogs.com/Blue233333/p/7553545.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!