zoukankan      html  css  js  c++  java
  • [BJOI2019]排兵布阵

    [BJOI2019]排兵布阵

    题面

    链接

    题解

    直接转化为分组背包

    #include<bits/stdc++.h>
    
    using namespace std;
    
    inline int read()
    {
        int f = 1 , x = 0;
        char ch;
        do
        {
            ch = getchar();
            if(ch=='-') f=-1;
        } while(ch<'0'||ch>'9');
        do
        {
            x=(x<<3) + (x<<1) + ch - '0';
            ch = getchar();
        }while(ch>='0'&&ch<='9');
        return f*x;
    }
    
    const int MAXN = 100 + 10;
    const int MAXM = 20000 + 10;
    
    int s,n,m;
    struct node
    {
        int v;
        int w;
    };
    vector<node>a[MAXN];
    int dp[MAXN][MAXM];
    
    inline bool cmp(node a,node b)
    {
        return a.v<b.v;
    }
    
    int main()
    {
        s = read(),n = read(),m = read();
        for(int j=1;j<=s;j++)
        {
            for(int i=1;i<=n;i++)
            {
                node x;
                x.v = read(),x.w=0;
                x.v=x.v*2+1;
                a[i].push_back(x);
            }
        }
        for(int i=1;i<=n;i++)
        {
            sort(a[i].begin(),a[i].end(),cmp);
            for(int j=1;j<=s;j++)
            {
                a[i][j-1].w = i*j;
            }
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=m;j>=0;j--)
            {
                dp[i][j] = dp[i-1][j];
                for(int k=1;k<=s;k++)
                {
                    if(j>=a[i][k-1].v)
                    dp[i][j] = max(dp[i][j],dp[i-1][j-a[i][k-1].v]+a[i][k-1].w);        
                }
            }
        }
        cout<<dp[n][m]<<endl;
    }

     

  • 相关阅读:
    IfcRoot
    IfcMaterial
    IfcDirection
    IfcAxis2Placement3D
    IfcBeam属性
    osg::Node源码
    不规则形状的Ifc构件顶点坐标获取
    不规则的Ifc构件顶点提取方法
    osg::Group源码
    Qt 图片缩放参数计算
  • 原文地址:https://www.cnblogs.com/wlzs1432/p/11723803.html
Copyright © 2011-2022 走看看