DP HDU 1712

ACboy needs your help

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

Total Submission(s): 4310    Accepted Submission(s): 2302

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

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <limits.h>
#include <ctype.h>
#include <string.h>
#include <string>
#include <queue>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <stack>
#include <deque>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define MAXN 111
int dp[MAXN];
int cost[MAXN][MAXN];

int main(){
    int n,m;
    int i,j,k;

    while(~scanf("%d%d",&n,&m)){
        if(n==0 && m==0){
            break;
        }
        memset(cost,0,sizeof(cost));
        memset(dp,0,sizeof(dp));
        for(i=1;i<=n;i++){
            for(j=1;j<=m;j++){
                scanf("%d",&cost[i][j]);
            }
        }
        for(i=1;i<=n;i++){
            for(j=m;j>=0;j--){
                for(k=1;k<=j;k++){
                    dp[j] = max(dp[j],dp[j-k]+cost[i][k]);//用各种天数来来完成i获得的最大的价值
                }
            }
        }
        cout<<dp[m]<<endl;
    }

    return 0;
}

时间: 2024-08-25 15:19:28

DP HDU 1712的相关文章

HDU 1712 ACboy needs your help(DP)

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

hdu 1712 ACboy needs your help

转载请注明出处:http://blog.csdn.net/u012860063 题目链接: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 depen

HDU 1712 ACboy needs your help AC男需要你的帮助 (AC代码)分组的背包问题

分组的背包问题:有N件物品和一个容量为V的背包.第i件物品的费用是c[i],价值是w[i].这些物品被划分为若干组,每组中的物品互相冲突,最多选一件.求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量,且价值总和最大. HDU 1712:AC男有m天时间可以上课,有n种课程可以选,但是每一种课程有各种的上课时长可选(因为并不是花的时间与收获就呈线性增长的,两者之间没什么对应关系,也许花1天收获2点经验,但是花2天就不是4点经验了,可能是3点而已).耗时与收获以矩阵的方式给出.(把同一课程

简单的dp hdu 数塔(水题)

数塔 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 21314    Accepted Submission(s): 12808 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少

fwt优化+树形DP HDU 5909

1 //fwt优化+树形DP HDU 5909 2 //见官方题解 3 // BestCoder Round #88 http://bestcoder.hdu.edu.cn/ 4 5 #include <bits/stdc++.h> 6 // #include <iostream> 7 // #include <cstdio> 8 // #include <cstdlib> 9 // #include <algorithm> 10 // #inc

I DP Hdu 1421

<span style="color:#3333ff;">/* ______________________________________________________________________________________________________ author : Grant Yuan time : 2014.7.19 algorithm : dp explain : 首先对所有的物体按照重量的从小到大进行一次排序,第i件物体只能和第i-1件物体配对;

dp --- hdu 4939 : Stupid Tower Defense

Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1219    Accepted Submission(s): 361 Problem Description FSF is addicted to a stupid tower defense game. The goal of tower

[数位dp] hdu 3967 Zero&#39;s Numberd

题意:对于两个数i和k,把它分为两个部分的数,n和m,如果(n+m)%k=0 那么这算一种分法 比如 333可分成,3.33或者33.3,对于 (333,3)就等于2. 现在给出 a.b.k,为 (a~b,k)有多少种分法 思路:对于一个数,注意前导零并枚举分点就好了. dp[22][22][22][22][2],   代表 i位,分点为fd,余数mod,对于k取余,是否有前导零 代码: #include"cstdlib" #include"cstdio" #inc

ACboy needs your help HDU - 1712

ACboy needs your help HDU - 1712 ans[i][j]表示前i门课共花j时间最大收益.对于第i门课,可以花k(0<=k<=j)时间,那么之前i-1门课共花j-k时间. 错误记录: 21行一个0写成1 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 int a[101][101],ans[101][101];