【BZOJ2073】【状压DP】[POI2004]PRZ 题解
来源:互联网 发布:北京数据所 编辑:程序博客网 时间:2024/05/23 01:23
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
#include <bits/stdc++.h>#define digit (ch < '0' || ch > '9')#define clr(x) memset(x, 0, sizeof x)#define ms(a, x) memset(x, a, sizeof x)using namespace std;template <class T> inline void read(T &x) { int flag = 1; x = 0; register char ch = getchar(); while( digit) { if(ch == '-') flag = -1; ch = getchar(); } while(!digit) { x = (x<<1)+(x<<3)+ch-'0'; ch = getchar(); } x *= flag;}const int maxn = 17;int w,n,dp[1<<maxn],tim[1<<maxn],sum[1<<maxn];int BIT[maxn],wei[maxn],t[maxn];int main () { read(w); read(n); BIT[0] = 1; ms(127/3, dp); for(int i = 1; i <= n; i++) read(t[i]), read(wei[i]); for(int i = 1; i < maxn; i++) BIT[i] = BIT[i-1]<<1; for(int i = 1; i < BIT[n]; i++) for(int j = 1; j <= n; j++) if(i&BIT[j-1]) tim[i] = max(tim[i], t[j]), sum[i] += wei[j]; dp[0] = 0; for(int i = 1; i < BIT[n]; i++) for(int j = i; j; j = i&(j-1)) if(sum[j] <= w) dp[i] = min(dp[i], tim[j]+dp[i^j]); printf("%d", dp[BIT[n]-1]); return 0;}
阅读全文
0 0
- 【BZOJ2073】【状压DP】[POI2004]PRZ 题解
- bzoj2073: [POI2004]PRZ 状压dp
- [bzoj2073][POI2004]PRZ 状压dp
- 【BZOJ2073】【POI2004】PRZ(状压dp)
- [BZOJ2073][POI2004]PRZ
- bzoj2073【POI2004】PRZ
- BZOJ2073: [POI2004]PRZ
- BZOJ2073 [POI2004]PRZ
- 【bzoj2073】[POI2004]PRZ
- 【BZOJ】【P2073】【POI2004】【PRZ】【题解】【状压DP+枚举子集】
- bzoj2083 [POI2004]PRZ 状压DP
- bzoj 2073:[POI2004]PRZ 状压DP
- 【bzoj2073】【[POI2004]PRZ】位运算枚举子集的特技
- bzoj 2073: [POI2004]PRZ
- BZOJ 2073: [POI2004]PRZ 状压动归
- bzoj2073
- 【bzoj2072】【poi2004】【MOS】【dp+贪心】
- BZOJ2067: [Poi2004]SZN 树形DP
- 滚动条的应用
- python numpy库数组的存取
- 字符串匹配问题
- Linux让程序不能被多次运行
- S
- 【BZOJ2073】【状压DP】[POI2004]PRZ 题解
- 内容超出后显示省略号
- 创建登录界面
- 图像内插
- D
- 我要找工作之排序相关
- 数据持久化 ( 存储 )
- tensorflow实现AlexNet
- 按钮布局演示