zoukankan      html  css  js  c++  java
  • Bzoj2073 [POI2004] PRZ

    Description

    一只队伍在爬山时碰到了雪崩,他们在逃跑时遇到了一座桥,他们要尽快的过桥. 桥已经很旧了, 所以它不能承受太重的东西. 任何时候队伍在桥上的人都不能超过一定的限制. 所以这只队伍过桥时只能分批过,当一组全部过去时,下一组才能接着过. 队伍里每个人过桥都需要特定的时间,当一批队员过桥时时间应该算走得最慢的那一个,每个人也有特定的重量,我们想知道如何分批过桥能使总时间最少.

    Input

    第一行两个数: w – 桥能承受的最大重量(100 <= w <= 400) 和 n – 队员总数(1 <= n <= 16). 接下来n 行每行两个数分别表示: t – 该队员过桥所需时间(1 <= t <= 50) 和 w – 该队员的重量(10 <= w <= 100).

    Output

    输出一个数表示最少的过桥时间.

    Sample Input

    100 3
    24 60
    10 40
    18 50

    Sample Output

    42

    状压DP,f[i]表示子集状态为i(二进制表示)时的最少用时

    BZOJ权限题。未评测。

     1 /*by SilverN*/
     2 #include<iostream>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<cmath>
     7 using namespace std;
     8 int pos[20];
     9 int f[1<<16],sum[1<<16],time[1<<16];
    10 int w[20],t[20];
    11 int tot,n;
    12 int main(){
    13     memset(f,32,sizeof f);
    14     scanf("%d%d",&tot,&n);
    15     int i,j;
    16     pos[0]=1;for(i=1;i<=16;i++)pos[i]=pos[i-1]<<1;
    17     for(i=1;i<=n;i++)scanf("%d%d",&t[i],&w[i]);
    18     for(i=1;i<pos[n];i++)
    19         for(j=1;j<=n;j++){
    20             if(i&pos[j-1]){
    21                 time[i]=max(time[i],t[j]);
    22                 sum[i]+=w[j];
    23             }
    24         }
    25     f[0]=0;
    26     for(i=1;i<pos[n];i++)
    27      for(j=i;j;j=i&(j-1)){
    28          if(sum[j]<=tot)f[i]=min(f[i],time[j]+f[i^j]);
    29      }
    30     printf("%d
    ",f[pos[n]-1]);
    31     return 0;
    32 }
  • 相关阅读:
    node.js 安装后怎么打开 node.js 命令框
    thinkPHP5 where多条件查询
    网站title中的图标
    第一次写博客
    Solution to copy paste not working in Remote Desktop
    The operation could not be completed. (Microsoft.Dynamics.BusinessConnectorNet)
    The package failed to load due to error 0xC0011008
    VS2013常用快捷键
    微软Dynamics AX的三层架构
    怎样在TFS(Team Foundation Server)中链接团队项目
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/5793797.html
Copyright © 2011-2022 走看看