hdu1712

题目链接:

点击打开链接

题目:

ACboy needs your help

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 3741    Accepted Submission(s): 1935

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

Source

HDU 2007-Spring Programming Contest

Recommend

lcy   |   We have carefully selected several similar problems for you:  2159 1561 3033 2955 1171

这是一个背包九讲里面的分组背包问题:

具体代码如下:

#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn=100+10;
int dp[maxn],a[maxn][maxn];
int main()
{
    int i,j,N,M,v;
    while(scanf("%d%d",&N,&M)!=EOF)
    {
        if(N==0&&M==0)  return 0;
        memset(dp,0,sizeof(dp));
        for(i=1;i<=N;i++)
            for(j=1;j<=M;j++)
               scanf("%d",&a[i][j]);
        for(i=1;i<=N;i++)
            for(v=M;v>=0;v--)
               for(j=1;j<=v;j++)
                dp[v]=max(dp[v],dp[v-j]+a[i][j]);
        printf("%d\n",dp[M]);
    }
    return 0;
}

hdu1712

时间: 2024-08-29 21:32:46

hdu1712的相关文章

【HDU1712】ACboy needs your help(分组背包)

将背包九讲往后看了看,学习了一下分组背包.来做几道入门题,试试手. 1 #include <iostream> 2 #include <cstring> 3 #include <cstdlib> 4 #include <cstdio> 5 #include <cmath> 6 #include <cctype> 7 #include <algorithm> 8 #include <numeric> 9 #inc

hdu1712 线性dp

1 //Accepted 400 KB 109 ms 2 //dp线性 3 //dp[i][j]=max(dp[i-1][k]+a[i][j-k]) 4 //在前i门课上花j天得到的最大分数,等于max(在前i-1门课上花k天+在第i门课上花j-k天得到的分数) 5 #include <cstdio> 6 #include <cstring> 7 #include <iostream> 8 #include <queue> 9 #include <cm

【hdu1712】分组背包(每组最多选1个)

[分组背包] [题意]ACboy要开始选课了,上一门课能够获得的收益和他上这门课的时间是有关的,然后给你若干门课,让你帮他进行选课,每一门课自然是只能选择一个课程时长,问你如何选择,才能使ACboy获得的受益最大. for(k=1;k<=K;k++) for(int v=V;v>=0;v--) for(int i=item in group k) f[v]=max(f[v],f[v-c[i]+w[i]);保证用到的都是k-1所更新的而不是k所更新的. 1 #include<cstdio&

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

http://acm.hdu.edu.cn/showproblem.php?pid=1712 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 arrang

HDU1712周期

ACboy needs your help Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5963    Accepted Submission(s): 3250 Problem Description ACboy has N courses this term, and he plans to spend at most M days

[hdu1712]ACboy needs your help分组背包

题意:一共$m$天,$n$门课程,每门课程花费$i$天得到$j$的价值,求最后获得的最大价值 解题关键:分组背包练习,注意循环的顺序不能颠倒 伪代码: $for$ 所有的组$k$   $for{\rm{ }}v = V..0$        $for$ 所有的$i$属于组$k$           $f[v] = \max (f[v],f[v] - c[i] + w[i])$ 背包问题本质上就是一种线性规划问题. 1 #include<bits/stdc++.h> 2 using namesp

hdu1712 分组背包

ACboy needs your help Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5964    Accepted Submission(s): 3251 Problem Description ACboy has N courses this term, and he plans to spend at most M days

HDU1712 ACboy needs your help(分组背包)

题目大意: 一个人在M天中完成N门课程,每门课程的分数和所用的时间有关系,求解如何安排学习得分最高. 输入:两个整数N和M,接下来是使一个N*M的矩阵A.A[i][j]代表用j天学习第i门课程的分数. 输出:得到的最大分数. 解题思路: 每门作业i只能选择一个对应的天数来完成,也就是矩阵的每一行中至多之能选择一个数,典型的分组背包问题: 分组背包: 有N件物品和一个容量为V的背包.第i件物品的费用是c[i],价值是w[i].这些物品被划分为若干组,每组中的物品互相冲突,最多选一件.求解将哪些物品

hdu1712 分组背包 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): 5022    Accepted Submission(s): 2714 Problem Description ACboy has N courses this term, and he plans to spend at most M days