zoukankan      html  css  js  c++  java
  • HDU1712ACboy 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
     
    解题思路:
    转化成01背包问题,利用j天复习第i门课视为一种物品,该物品的体积为j,价值为m[i][j],要注意的是每门课只能选一次
     
    AC代码:
    #include<iostream> #include<math.h> #include<stdio.h> #include<string.h> using namespace std; int DP[5000],m[5000][5000],N,M; int w[5000],v[5000]; int max(int x,int y) { return (x>y? x:y); } int main () { while(scanf("%d%d",&N,&M)&&(N||M)) {   memset(DP,0,sizeof(DP));   for(int i=1;i<=N;++i)   for(int j=1;j<=M;++j)   scanf("%d",&m[i][j]);   for(int i=1;i<=N;++i)   for(int j=M;j>=1;--j)   for(int k=1;k<=j;++k)   DP[j]=max(DP[j],DP[j-k]+m[i][k]);   printf("%d\n",DP[M]); } return 0; }
  • 相关阅读:
    数字建模工具
    博客园文档保存为pdf适合手机kindle阅读
    单点登录sso规范
    office在线预览方案
    KVM 虚机怎么热添加disk
    linux-基础FTP 协议传输
    TCP 三次握手四次挥手
    autossh 实现反向代理实现通过外网访问内网环境
    keepalived的工作原理
    openstack-ovs命令记录
  • 原文地址:https://www.cnblogs.com/xiaxiaosheng/p/3020396.html
Copyright © 2011-2022 走看看