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<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std; int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==0||m==0)
{
break;
}
long long int dp[105];
int a[105][105];
memset(dp,0,sizeof(dp));
memset(a,0,sizeof(a)); for(int t=1;t<=n;t++)
{
for(int j=1;j<=m;j++)
{
scanf("%d",&a[t][j]);
}
}
for(int t=1;t<=n;t++)
{
for(int j=m;j>=0;j--)
{
for(int k=0;k<=j;k++)
{
dp[j]=max(dp[j],dp[j-k]+a[t][k]);
}
}
}
printf("%lld\n",dp[m]);
}
return 0;
}

ACboy needs your help (动态规划背包)的更多相关文章

  1. HDU 1712 ACboy needs your help(包背包)

    HDU 1712 ACboy needs your help(包背包) pid=1712">http://acm.hdu.edu.cn/showproblem.php? pid=171 ...

  2. Bzoj 1042: [HAOI2008]硬币购物 容斥原理,动态规划,背包dp

    1042: [HAOI2008]硬币购物 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1747  Solved: 1015[Submit][Stat ...

  3. Leetcode 494 Target Sum 动态规划 背包+滚动数据

    这是一道水题,作为没有货的水货楼主如是说. 题意:已知一个数组nums {a1,a2,a3,.....,an}(其中0<ai <=1000(1<=k<=n, n<=20) ...

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

    http://acm.hdu.edu.cn/showproblem.php?pid=1712 Problem Description ACboy has N courses this term, an ...

  5. hdu 3008:Warcraft(动态规划 背包)

    Warcraft Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  6. hdu1712 ACboy needs your help 分组背包

    最基础的分组背包~ #include <iostream> #include <cstdio> #include <cstdlib> #include <cs ...

  7. HDU 1712 ACboy needs your help (分组背包模版题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 有n门课,和m天时间.每门课上不同的天数有不同的价值,但是上过这门课后不能再上了,求m天里的最大 ...

  8. hdu 1712 ACboy needs your help 分组背包

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 Problem ...

  9. POJ_2184_Cow_Exhibition_(动态规划,背包)

    描述 http://poj.org/problem?id=2184 n只奶牛,每只都有智商s_i和情商f_i,取出若干只,保证智商之和与情商之和都不为负的情况下,让两者之和最大. Cow Exhibi ...

随机推荐

  1. map,reduce和filter函数

    numArray = [1, 2, 3, 4, 5] def ercifang(x): return x ** 2 def map_test(func, numArray): li = [] for ...

  2. URL中加号(+)转义问题

    URL中加号(+)转义问题 前端通过URL传入一个参数,在后台日志中发现参数中的加号变成了空格. 前端传入a+b 后台日志a b 可以看到,+ 变成了空格. 先说结论 HTTP为了避免歧义,一些字符传 ...

  3. Linux查询版本、查询端口

    lsb_release -a 查看当前Linux系统版本 netstat 检查端口 netstat 是一个命令行工具,可以提供有关网络连接的信息.要列出正在侦听的所有 TCP 或 UDP 端口,包括使 ...

  4. 2020-04-13:TCP协议本身会导致什么样的安全问题?

    福哥答案2020-04-14: 洪泛攻击    

  5. Visual Studio 2019预览,净生产力

    本文章为机器翻译. https://blogs.msdn.microsoft.com/dotnet/2018/12/13/visual-studio-2019-net-productivity/ 该文 ...

  6. .Net微服务实战之Kubernetes的搭建与使用

    系列文章 .Net微服务实战之技术选型篇 .Net微服务实战之技术架构分层篇 .Net微服务实战之DevOps篇 .Net微服务实战之负载均衡(上) .Net微服务实战之CI/CD 前言 说到微服务就 ...

  7. RNN以及LSTM简介

    转载地址 https://blog.csdn.net/zhaojc1995/article/details/80572098 本文部分参考和摘录了以下文章,在此由衷感谢以下作者的分享! https:/ ...

  8. Linux下如何高效切换目录?

    Linux 下对于目录的切换,大家肯定会想到一个命令:cd 命令.这个是 Linux 下再基本不过的命令,如果这个命令都不知道的话,赶紧剖腹自尽去吧. cd 命令确实很方便,但如果需要频繁在下面的目录 ...

  9. 实型(浮点型):float、double

    #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> #include<stdlib. ...

  10. 浅谈:什么是.NET

    .NET是 Microsoft XML Web services 平台.XML Web services 允许应用程序通过 Internet 进行通讯和共享数据,而不管所采用的是哪种操作系统.设备或编 ...