首页 > 其他 > 详细

[BJOI2019]排兵布阵

时间:2019-10-23 09:11:05      阅读:72      评论:0      收藏:0      [点我收藏+]

[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;
}

 

 

[BJOI2019]排兵布阵

原文:https://www.cnblogs.com/wlzs1432/p/11723803.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!