首页 > 其他分享 >HDU 1712 ACboy needs your help

HDU 1712 ACboy needs your help

时间:2022-10-25 17:07:58浏览次数:77  
标签:1712 HDU help ACboy int profit days courses include


题目链接:​​传送门​​ 题面:


ACboy needs your help

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

题意:

你有天要学门课,表示第门课花了天你可以获得的价值,求如何选择课程能使得你获得的价值最大。

分组背包
一组物品就是每一门课的不同价值
只能取一次
先枚举组数
再枚举体积
再枚举每组中的物品

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <vector>
#include <iomanip>
#define
#define
#define

using namespace std;
int f[A], n, m, a[B][B];

int main() {
while (scanf("%d%d", &n, &m)) {
if (!n and !m) return 0;
memset(f, 0, sizeof f);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
scanf("%d", &a[i][j]);
for (int i = 1; i <= n; i++)
for (int j = m; j >= 0; j--)
for (int k = 1; k <= m; k++)
f[j] = max(f[j], f[j - k] + a[i][k]);
printf("%d\n", f[m]);
}
}


标签:1712,HDU,help,ACboy,int,profit,days,courses,include
From: https://blog.51cto.com/lyle/5794942

相关文章

  • HDU 2159 FATE
    题目链接:​​传送门​​题面:FATEProblemDescription最近xhd正在玩一款叫做FATE的游戏,为了得到极品装备,xhd在不停的杀怪做任务。久而久之xhd开始对杀怪产生的厌恶感,但又......
  • HDU 3466 Pround Merchants
    题目链接:​​传送门​​题面:ProudMerchantsProblemDescriptionRecently,iSeawenttoanancientcountry.Forsuchalongtime,itwasthemostwealthyandpow......
  • HDU 1171 Big Event In HDU
    题目链接:​​传送门​​BigEventinHDUProblemDescriptionNowadays,weallknowthatComputerCollegeisthebiggestdepartmentinHDU.But,maybeyoudon’t......
  • HDU 3535 AreYouBusy
    题目链接:​​传送门​​题面:AreYouBusyProblemDescriptionHappyNewTerm!Ashavingbecomeajunior,xiaoArecognizesthatthereisnotmuchtimeforhertoAC......
  • HDU 2844 Coins
    题目链接:​​传送门​​​题面:ProblemDescriptionWhuacmersusecoins.TheyhavecoinsofvalueA1,A2,A3…AnSilverlanddollar.OnedayHibixopenedpurseandfoun......
  • HDU 1203 I NEED A OFFER!
    题目链接:​​传送门​​题面:INEEDAOFFER!ProblemDescriptionSpeakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要准备的材料,于是,便需要去申请学校了......
  • HDU 1114 Piggy-Bank
    题目链接:​​传送门​​Piggy-BankProblemDescriptionBeforeACMcandoanything,abudgetmustbepreparedandthenecessaryfinancialsupportobtained.Them......
  • HDU 2546 饭卡
    题目链接:​​传送门​​题面:ProblemDescription电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一......
  • HDU 2602 Bone Collector
    题目链接:​​传送门​​​题面:ProblemDescriptionManyyearsago,inTeddy’shometowntherewasamanwhowascalled“BoneCollector”.Thismanliketocollec......
  • DocumentHelper.parseText dom4j 前言中不允许有内容
    org.dom4j.DocumentException:Erroronline1ofdocument:前言中不允许有内容百度了一下,才发现是文件编码问题。1.用记事本打开xml文件转化为UTF-8会有一个BOM头,所......