HDU 1712 ACboy needs your help 多组背包
来源:互联网 发布:ubuntu pyqt4安装 编辑:程序博客网 时间:2024/06/05 21:04
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1712
题意:用m天的时间来学n门课程,给出n和m和一个num[n][m]的矩阵,num[n][m] 代表的是花m天的时间学习第n门课程所获得的价值,求最多能获得多大的价值
思路:将天数m作为背包的总体积,科目数目作为背包的种类数目,天数j作为背包的重量,num[i][j]作为背包的价值。由于一个科目只能选一次,即满足一组背包只能选一个,即转化为多组背包问题。
代码:
#include <iostream>#include <string.h>#include <cstdio>using namespace std;#define CLR(arr,val) memset(arr,val,sizeof(arr))const int N = 110;int num[N][N],dp[N];struct course{int val,weight;}cc[110];int main(){//freopen("1.txt","r",stdin);int numkind,totalweight;while(scanf("%d%d",&numkind,&totalweight) &&numkind&&totalweight){ CLR(num,0); int x; for(int i = 1;i <= numkind;++i){ for(int j = 1;j <= totalweight;++j){ scanf("%d",&num[i][j]); } } CLR(dp,0); for(int i = 1;i <= numkind;++i){ for(int w = totalweight;w > 0;--w){ for(int j = 0;j <= totalweight;++j){ if(w >= j) dp[w] = max(dp[w],dp[w - j] + num[i][j]); } } } int mmax = 0; for(int i = 0;i <= totalweight;++i) if(mmax < dp[i]) mmax = dp[i]; printf("%d\n",mmax);}return 0;}
- HDU 1712 ACboy needs your help 多组背包
- HDU 1712 ACboy needs your help(背包)
- hdu 1712 ACboy needs your help 分组背包
- hdu 1712 ACboy needs your help(分组背包入门题)
- HDU 1712 ACboy needs your help(分组背包)
- 【hdu 1712】ACboy needs your help (分组背包)
- hdu 1712 ACboy needs your help (分组背包)
- hdu 1712 ACboy needs your help(分组背包)
- hdu 1712 ACboy needs your help(分组背包)
- HDU 1712 01背包 ACboy needs your help
- HDU 1712 ACboy needs your help ----分组背包
- hdu 1712 ACboy needs your help (分组背包)
- hdu 1712 ACboy needs your help(分组背包)
- HDU 1712 ACboy needs your help(DP 分组背包)
- hdu 1712 ACboy needs your help (分组背包)
- hdu 1712 ACboy needs your help(分组背包)
- hdu 1712ACboy needs your help 01背包(分组)
- HDU 1712 ACboy needs your help (分组背包)
- MyEclipse配置findbugs
- mysql sql语句大全
- 系统闹钟程序知识点记录
- 套接字编程中,select:bad file descriptor
- Linux清除正在写的文件内容(比如nohup.out)
- HDU 1712 ACboy needs your help 多组背包
- AIDL sample
- PHP的三目运算符
- SQL Server 2008 数据维护实务
- 几个有用的iOS开源代码
- OCX和DLL的区别
- 文件描述符、文件表项、V节点表项的一些总结
- 28个Unix/Linux的命令行神器
- php_server详解