zoukankan      html  css  js  c++  java
  • 资源分配(分组背包)

    #include <iostream>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <cctype>
    #include <vector>
    #include <iterator>
    #include <set>
    #include <map>
    #include <sstream>
    using namespace std;
    
    #define mem(a,b) memset(a,b,sizeof(a))
    #define pf printf
    #define sf scanf
    #define spf sprintf
    #define pb push_back
    #define debug printf("!
    ")
    #define MAXN 1010
    #define MAX(a,b) a>b?a:b
    #define blank pf("
    ")
    #define LL long long
    #define ALL(x) x.begin(),x.end()
    #define INS(x) inserter(x,x.begin())
    #define pqueue priority_queue
    #define INF 0x3f3f3f3f
    
    int n,m;//m个车间,n个机器
    
    int mapp[105][105];//mapp[i][j]为第i个车间使用j个机器的利润
    
    int dp[105];//dp[x]表示x个机器最多能得到的利润
    
    int main()
    {
        int i,j,k;
        while(~sf("%d%d",&n,&m) && m+n)
        {
            mem(dp,0);
            for(i=1;i<=m;i++)//m组
            {
                for(j=1;j<=n;j++)//n容量
                {
                    sf("%d",&mapp[i][j]);
                }
            }
    
            for(i=1;i<=m;i++)//m组
            {
                for(j=n;j>=1;j--)//n容量
                {
                    for(k=1;k<=n;k++)//该组的每一个物品
                    {
                        if(k<=j) dp[j] = max(dp[j],dp[j-k]+mapp[i][k]);
                    }
                }
            }
            pf("%d
    ",dp[n]);
        }
        return 0;
    }
  • 相关阅读:
    HDU
    HDU
    HDU
    HDU
    HDU
    P6146 [USACO20FEB]Help Yourself G 组合数学 DP
    CodeForces
    POJ
    【网络学习】集线器,交换机,路由器的作用
    【Python学习】深拷贝和浅拷贝
  • 原文地址:https://www.cnblogs.com/qlky/p/6197211.html
Copyright © 2011-2022 走看看