Bookshelf 2 -- 动态规划01背包稍作改变
来源:互联网 发布:mac上的安卓模拟器 编辑:程序博客网 时间:2024/06/02 14:38
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int cow[25];
int value[25];
int height[1000000];
int bad[1000000];
int main()
{
int sum=0;
int n,m;
int count=0;
scanf("%d %d",&n,&m);
memset(bad,0,sizeof(bad));
for(int i = 1;i<=n;i++)
{
scanf("%d",&cow[i]);
value[i] = cow[i];
sum += value[i];
}
for(int i = 1;i<=n;i++)
{
for(int j =sum;j>=cow[i];j--)
{
height[j] = max(height[j-cow[i]]+value[i],height[j]);
}
}
for(int i = 0;i<=sum;i++)
{
if(height[i]>=m)
{
printf("%d",height[i]-m);
break;
}
}
}
#include <cstring>
#include <algorithm>
using namespace std;
int cow[25];
int value[25];
int height[1000000];
int bad[1000000];
int main()
{
int sum=0;
int n,m;
int count=0;
scanf("%d %d",&n,&m);
memset(bad,0,sizeof(bad));
for(int i = 1;i<=n;i++)
{
scanf("%d",&cow[i]);
value[i] = cow[i];
sum += value[i];
}
for(int i = 1;i<=n;i++)
{
for(int j =sum;j>=cow[i];j--)
{
height[j] = max(height[j-cow[i]]+value[i],height[j]);
}
}
for(int i = 0;i<=sum;i++)
{
if(height[i]>=m)
{
printf("%d",height[i]-m);
break;
}
}
}
阅读全文
0 0
- Bookshelf 2 -- 动态规划01背包稍作改变
- POJ3628:Bookshelf 2【01背包】
- POJ3628:Bookshelf 2【01背包】
- POJ3628 Bookshelf 2(01背包)
- Bookshelf 2(01背包)(深搜)
- 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背包
- poj3628 Bookshelf 2 DP 01背包
- POJ 3628 Bookshelf 2 (01背包)
- poj 3628 Bookshelf 2(01背包)
- 【POJ3628】Bookshelf 2 01背包,水题
- poj 3628 Bookshelf 2 (01背包)
- Bookshelf 2(01背包题目4)
- iTOP4412 安装NFS服务器
- Android Wi-Fi 四次握手简介
- 大数据和空间限制问题
- [LintCode]372.在O(1)时间复杂度删除链表节点
- Yocto 支持从sysvinit 到 systemd
- Bookshelf 2 -- 动态规划01背包稍作改变
- HDU 3333 Turing Tree (离线线段树,经典)
- Python_matlab_01
- 第一次发表博客
- 冒泡事件
- 制作jffs2根文件系统
- 模仿ofo小黄人眼睛跟随手机移动
- 欢迎使用CSDN-markdown编辑器
- PAT (Advanced Level) Practise 1071 Speech Patterns (25)