P1757 通天之分组背包

hdu1712 ACboy needs your help

hdu1712题意:A[i][j]表示用j天学习第i个课程能够得到A[i][j]的收益,求m天内获得的收益最大值,一天只能上一节课(转)。

分组背包套路:

for(int i=;i<=组数;++i)
for(int j=容量;j>=;--j)
for(int k=;k<=第i组元素个数;++k)
…………

保证一组只选<=1个

 #include<iostream>
#include<cstdio>
#include<cstring>
#define re register
using namespace std;
int max(int &a,int &b){return a>b?a:b;}
int n,m,a[][],f[];
int main(){
while(~scanf("%d%d",&n,&m)){
if(!n&&!m) break;
for(re int i=;i<=n;++i)
for(re int j=;j<=m;++j)
scanf("%d",&a[i][j]);
memset(f,,sizeof(f));
for(re int i=;i<=n;++i)
for(re int j=m;j>=;--j)
for(re int k=;k<=j;++k)
f[j]=max(f[j],f[j-k]+a[i][k]);
printf("%d\n",f[m]);
}return ;
}

hdu1712 code

 #include<iostream>
#include<cstdio>
#include<cstring>
#define re register
using namespace std;
int max(int &a,int &b){return a>b?a:b;}
int n,m,f[];
int len[],a[][],b[][];
int main(){
int q1,q2,q3,mc;
while(~scanf("%d%d",&m,&n)){
memset(len,,sizeof(len));
memset(f,,sizeof(f));
mc=;
for(re int i=;i<=n;++i){
scanf("%d%d%d",&q1,&q2,&q3);
mc=max(mc,q3);
a[q3][++len[q3]]=q1;
b[q3][len[q3]]=q2;
}
for(re int i=;i<=mc;++i)
for(re int j=m;j>=;--j)
for(re int u=;u<=len[i];++u)
if(j>=a[i][u])
f[j]=max(f[j],f[j-a[i][u]]+b[i][u]);
printf("%d\n",f[m]);
}return ;
}

P1757 code

P1757 通天之分组背包 / hdu1712 ACboy needs your help (分组背包入门)的更多相关文章

  1. HDU1712:ACboy needs your help(分组背包模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1712 Problem Description ACboy has N courses this term, an ...

  2. hdu1712 ACboy needs your help 分组背包

    最基础的分组背包~ #include <iostream> #include <cstdio> #include <cstdlib> #include <cs ...

  3. 分组背包----HDU1712 ACboy needs your help

    很简单的一道分组背包入门问题.不多解释了. #include <iostream> #include <cstdio> #include <cstring> usi ...

  4. [hdu1712]ACboy needs your help分组背包

    题意:一共$m$天,$n$门课程,每门课程花费$i$天得到$j$的价值,求最后获得的最大价值 解题关键:分组背包练习,注意循环的顺序不能颠倒 伪代码: $for$ 所有的组$k$   $for{\rm ...

  5. P1757 通天之分组背包

    P1757 通天之分组背包背包中的经典问题,我竟然不知道.分组背包就是每个物品有一个所属的小组,小组内的物品会冲突.就是把01背包中的两个for换一下位置01:for(i,1,kind) for(j, ...

  6. 洛谷——P1757 通天之分组背包

    P1757 通天之分组背包 题目背景 直达通天路·小A历险记第二篇 题目描述 自01背包问世之后,小A对此深感兴趣.一天,小A去远游,却发现他的背包不同于01背包,他的物品大致可分为k组,每组中的物品 ...

  7. 洛谷 P1757 通天之分组背包

    P1757 通天之分组背包 题目背景 直达通天路·小A历险记第二篇 题目描述 自01背包问世之后,小A对此深感兴趣.一天,小A去远游,却发现他的背包不同于01背包,他的物品大致可分为k组,每组中的物品 ...

  8. 分组背包---P1757 通天之分组背包

    P1757 通天之分组背包 题解 分组背包板子题 k组物品,每组之间相互矛盾,也就是一组里面只能选一个或者不选 分组背包其实和01背包差不多,就是多加一维枚举组数 f[k][j] 前k组中,体积不超过 ...

  9. 洛谷P1757 通天之分组背包 [2017年4月计划 动态规划06]

    P1757 通天之分组背包 题目背景 直达通天路·小A历险记第二篇 题目描述 自01背包问世之后,小A对此深感兴趣.一天,小A去远游,却发现他的背包不同于01背包,他的物品大致可分为k组,每组中的物品 ...

随机推荐

  1. js 判断数据类型的几种方法

    判断js中的数据类型有一下几种方法:typeof.instanceof. constructor. prototype. $.type()/jquery.type(),接下来主要比较一下这几种方法的异 ...

  2. mySQL数据库三:命令行附录

    一:where 在上一篇,粗略的介绍了where,但是where后面可以跟其他的条件,现在我们来一一说明 1.between:在某两个值之间 我建立一个名为person的表,里面有id,name,ag ...

  3. Delphi Code Editor 之 几个特性(转)

    Delphi Code Editor有几个特性在编写大规模代码时非常有用.下面分别进行介绍: 原地址:http://www.cnblogs.com/pchmonster/category/343330 ...

  4. web基础---->Fileupload文件的上传

    这里我们介绍文件上传的知识,使用的是apache的Commons FileUpload框架. 文件上传的使用 项目的部分结构如下: 一.使用Commons FileUpload的上传功能,我们需要引入 ...

  5. 【BZOJ2946】[Poi2000]公共串 后缀数组+二分

    [BZOJ2946][Poi2000]公共串 Description        给出几个由小写字母构成的单词,求它们最长的公共子串的长度. 任务: l        读入单词 l        计 ...

  6. web站点检查简易shell脚本

    1.web样式 <h4>THE STATUS OF RS:</h4> <meta http-equiv="> <table border=" ...

  7. Windows系统下做定时任务为Oracle数据库每天自动备份

    1.创建备份目录d:\backup, 创建批处理命令Bak.bat,编写备份脚本 ? 1 2 exp user/passwd@orcl DIRECT=Y BUFFER=100000 FILE=D:\b ...

  8. "errmsg" : "distinct too big, 16mb cap",

    repl_test:PRIMARY> show dbs admin 0.000GB direct_vote_resource 16.487GB local 14.860GB personas 3 ...

  9. 【Loadrunner】性能测试:通过服务器日志获取性能需求

    性能测试:通过服务器日志获取性能需求          接触过性能测试的童鞋都知道,想要做好一个项目的性能测试,性能需求的获取至关重要~!如果公司有做过性能测试还好,大家可以拿之前的性能测试数据作为参 ...

  10. conda

    Conda是什么? Conda 是Anaconda下用于包管理和环境管理的命令行工具, Conda下一切都是包,包括Python和conda自己 Conda ≍ pip(包管理) + vitualen ...