zoukankan      html  css  js  c++  java
  • 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
    ",ans);
    31     return 0;
    32 }
    View Code
  • 相关阅读:
    自定义ProgressBar
    Anroid开发中常用快捷键
    Intent用法
    IO(Input Output)流
    自定义Dialog
    仿UC点击两次返回键退出程序
    横竖屏切换时Activity的生命周期
    单例模式
    Timer用法
    关于数组
  • 原文地址:https://www.cnblogs.com/Blue233333/p/7553545.html
Copyright © 2011-2022 走看看