HDUOJ---1712 ACboy needs your help
ACboy needs your help
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3282 Accepted Submission(s): 1703
Problem Description
ACboy has N courses this term, and he plans to spend at most M days on study.Of course,the profit he will gain from different course depending on the days he spend on it.How to arrange the M days for the N courses to maximize the profit?
Input
The input consists of multiple data sets. A data set starts with a line containing two positive integers N and M, N is the number of courses, M is the days ACboy has. Next follow a matrix A[i][j], (1<=i<=N<=100,1<=j<=M<=100).A[i][j] indicates if ACboy spend j days on ith course he will get profit of value A[i][j]. N = 0 and M = 0 ends the input.
Output
For each data set, your program should output a line which contains the number of the max profit ACboy will gain.
Sample Input
2 2
1 2
1 3
2 2
2 1
2 1
2 3
3 2 1
3 2 1
0 0
Sample Output
3
4
6
分组背包!....
1 /*o1背包@龚细军*/
2 /*维度为2的01背包*/
3 #include<stdio.h>
4 #include<string.h>
5 #define maxn 102
6 int dp[maxn];
7 int aa[maxn][maxn];
8
9 int max(int a,int b)
10 {
11 return a>b?a:b;
12 }
13 int main()
14 {
15 int m,n,i,j,k;
16 while(scanf("%d%d",&n,&m),m+n)
17 {
18 memset(dp,0,sizeof(dp));
19 for(i=1;i<=n;i++) // class
20 for(j=1;j<=m;j++) //day
21 scanf("%d",&aa[i][j]);
22 //对每一门课程进行背包施放
23 for(i=1;i<=n;i++)
24 {
25 for(j=m;j>=0;j--) //代表的是背包的容量
26 {
27 for(k=1;k<=j;k++) //在这个容量内选择一个房间去,和之前放进去的比较!
28 dp[j]=max(dp[j],dp[j-k]+aa[i][k]);
29 }
30 }
31 printf("%dn",dp[m]);
32 }
33 return 0;
34 }
- 【下载】苹果发布Turi Create机器学习框架,5行代码开发图像识别
- codevs 4163 hzwer与逆序对
- ASP.NET Core提供模块化Middleware组件
- CSS预处理器的对比 — sass、less和stylus
- Gensim实现Word2Vec的Skip-Gram模型简介快速上手对语料进行分词使用gensim的word2vec训练模型
- React第三方组件4(状态管理之Reflux的使用②TodoList上)
- 机器学习(六)Sigmoid函数和Softmax函数1 Sigmoid函数2 Softmax函数
- React第三方组件4(状态管理之Reflux的使用①简单使用)
- React第三方组件3(状态管理之Flux的使用⑤异步操作)
- 使用yo-get下载视频网站视频或其
- React多页面应用3(webpack4 多页面实现)
- 洛谷P2345 奶牛集会
- React多页面应用2(webpack4 处理CSS及图片,引入postCSS,及图片处理等)
- React多页面应用1(webpack4 开发环境搭建,包括热更新,api转发等)
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- MUI框架中使用百度地图(全网独一份最详细的图文教程)
- 0792-5.16.2-如何通过Hive跨集群迁移Kudu表
- [解决]Docker中安装Centos7后无法正常使用命令
- 毕业设计之「测试实验及结果分析」(一)
- 【DB笔试面试845】在Oracle中,sqlnet.ora文件的作用是什么?
- 安卓-无敌解决ListView添加标题头无法正常显示的问题(歪门邪道)
- 贪心算法-活动选择问题(Python实现)
- 浅析C语言中一些“令人吃惊”的结构
- 贪心算法-分数背包问题(Python实现)
- 为什么GNE 不做全自动提取列表页的功能
- 百度地图开发如何自定义控件(无敌的解决办法)
- 百度地图如何创建一个属于自己的地图,附加到项目中?
- FreeRTOS系列第9篇---FreeRTOS任务概述基础篇
- 图书管理系统(四)图书管理系统实战(2)
- 源码分析之 FactoryBean接口不为人知的秘密