poj 3628 Bookshelf 2(01背包)
来源:互联网 发布:手机淘宝如何退保证金 编辑:程序博客网 时间:2024/05/18 00:58
有n头牛,摞在一块,让他们的高度超过B,从超过B的高度中,找到最小的那个,求他和B的差。
以所有牛摞一块的高度为背包
#include <stdio.h>#define max(a,b) a>b?a:b#define min(a,b) a>b?b:aconst int MAXN = 20000010;int N,B,sum = 0;int height[25];int dp[MAXN];void solve(){ for(int i = 0; i < N; ++i) { for(int j = sum; j >= height[i]; --j) dp[j] = max(dp[j],dp[j-height[i]]+height[i]); }}int main(){ scanf("%d %d",&N,&B); for(int i = 0; i < N; ++i) { scanf("%d",&height[i]); sum += height[i]; } solve(); int res = MAXN; for(int i = sum; i >= B; --i) { if(dp[i]-B >= 0) res = min(dp[i]-B,res); else break; } printf("%d\n",res); return 0;}
阅读全文
0 0
- poj 3628 Bookshelf 2 01背包
- poj 3628 Bookshelf 2 01背包!!!
- poj 3628 Bookshelf 2 01背包
- POJ 3628 Bookshelf 2 (01背包)
- [01背包]POJ 3628 Bookshelf 2
- POJ 3628 Bookshelf 2(DP:01背包)
- poj 3628 Bookshelf 2 01背包
- POJ 3628 Bookshelf 2 (01背包)
- poj 3628 Bookshelf 2(01背包)
- poj 3628 Bookshelf 2 (01背包)
- 【POJ 3628】Bookshelf 2(01背包)
- POJ 3628 Bookshelf 2 (01背包)
- POJ-3628--Bookshelf 2--01背包
- poj 3628 Bookshelf 2(01背包)
- POJ 3628 Bookshelf 2(背包)
- poj 3628 Bookshelf 2 背包
- poj 3628 Bookshelf 2(01背包入门或者dfs)
- 简单01背包问题求解 POJ:3628 Bookshelf 2
- python学习笔记之011.py
- mysql 如何用一个表的字段填充另一个表
- Java虚拟机发展史
- java书籍
- C++ STL中的map和vector
- poj 3628 Bookshelf 2(01背包)
- mybatis之动态sql(八)
- vijos1067 Warcraft III 守望者的烦恼(矩阵倍增)
- ScrollView反弹效果 仿小米私密短信效果
- ArrayAvg
- log4j.properties 的使用详解
- Ants
- [python]map方法与并行执行
- C# 调用rest接口 cookie的保持