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. 使用area标签实现标签的嵌套

    在项目中我们会碰到这种需求:即点击这个整个a标签跳转到一个页面,点击a里面的某个a再跳转到另一个页面.有人会说,这还不简单,直接a标签嵌套a标签,可是事实如此吗,看代码: <a href=&qu ...

  2. 使用类/结构体时关于ZeroMomery用法错误

    今天同事在写了如下结构体: typedef struct _tagInfo { std::list<int> lst; std::vector<int> nVec; } INF ...

  3. iGson

    头文件 #import <Foundation/Foundation.h> #import <objc/runtime.h> #import "NSString+Ut ...

  4. [css]演示:纯CSS实现的右侧底部简洁悬浮效果

    <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <meta name ...

  5. iOS 8 新特性介绍

    来源:nshipster.cn 发布时间:2014-07-06 阅读次数:2152 随便去问任何人,他们都会告诉你WWDC2014是近年来最为激动的回忆. 整个大会没有发布任何新硬件,它是一次史无前例 ...

  6. php 自带的过滤函数和转义函数

    函数名 释义 介绍 htmlspecialchars 将与.单双引号.大于和小于号化成HTML格式 &转成&"转成"' 转成'<转成<>转成> ...

  7. HDU 1103 Flo's Restaurant(模拟+优先队列)

    Flo's Restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. 牛客网多校赛第七场A--Minimum Cost Perfect Matching【位运算】【规律】

    链接:https://www.nowcoder.com/acm/contest/145/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...

  9. nginx 下使用 bootstrap 字体的问题

    使用boostrap时,出现 glyphicons-halflings-regular.ttf glyphicons-halflings-regular.woff glyphicons-halflin ...

  10. Python量化教程 常用函数

    # -*- coding: utf-8 -*- # @Author: fangbei # @Date: 2017-08-26 # @Original: price_str = '30.14, 29.5 ...