zoukankan      html  css  js  c++  java
  • 【LOJ】#3092. 「BJOI2019」排兵布阵

    LOJ#3092. 「BJOI2019」排兵布阵

    这题就是个背包啊,感觉是(nms)的但是不到0.2s,发生了什么。。

    就是设(f[i])为选了(i)个人最大的代价,然后有用的人数只有(s)

    #include <bits/stdc++.h>
    #define fi first
    #define se second
    #define pii pair<int,int>
    #define mp make_pair
    #define pb push_back
    #define space putchar(' ')
    #define enter putchar('
    ')
    #define eps 1e-10
    #define MAXN 500005
    #define ba 47
    //#define ivorysi
    using namespace std;
    typedef long long int64;
    typedef unsigned int u32;
    typedef double db;
    template<class T>
    void read(T &res) {
        res = 0;T f = 1;char c = getchar();
        while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
        }
        while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
        }
        res *= f;
    }
    template<class T>
    void out(T x) {
        if(x < 0) {x = -x;putchar('-');}
        if(x >= 10) {
    	out(x / 10);
        }
        putchar('0' + x % 10);
    }
    int64 f[20005];
    int a[105][105],S,N,M;
    vector<int> v;
    vector<pii > vec;
    
    void upmax(int64 &x,int64 y) {
        x = max(x,y);
    }
    void Solve() {
        read(S);read(N);read(M);
        for(int i = 1 ;i <= S ; ++i) {
    	for(int j = 1 ; j <= N ; ++j) {
    	    read(a[i][j]);
    	}
        }
        for(int j = 1 ; j <= N ; ++j) {
    	v.clear();vec.clear();
    	for(int i = 1 ; i <= S ; ++i) {
    	    if(a[i][j] * 2 + 1 <= M) v.pb(a[i][j] * 2 + 1);
    	}
    	sort(v.begin(),v.end());
    	if(v.size()) {
    	    vec.pb(mp(v[0],1));
    	    for(int i = 1 ; i < v.size() ; ++i) {
    		pii t = vec.back();
    		if(v[i] == v[i - 1]) {
    		    t.se++;vec.pop_back();vec.push_back(t);
    		}
    		else vec.pb(mp(v[i],t.se + 1));
    	    }
    	}
    	for(int i = M ; i >= 0 ; --i) {
    	    for(auto t : vec) {
    		if(i >= t.fi) {
    		    upmax(f[i],f[i - t.fi] + 1LL * t.se * j);
    		}
    		else break;
    	    }
    	}
        }
        out(f[M]);enter;
    }
    int main() {
    #ifdef ivorysi
        freopen("f1.in","r",stdin);
    #endif
        Solve();
    }
    
  • 相关阅读:
    人脸识别经典算法三:Fisherface(LDA)
    人脸识别经典算法二:LBP方法
    特征脸(Eigenface)理论基础-PCA(主成分分析法)
    人脸识别经典算法一:特征脸方法(Eigenface)
    文本特征词提取算法
    浏览器假死,浏览器堵塞,浏览器卡的原因
    Java世界里的四大名著(Java程序员必看书籍)
    mySQL中LEN()与DATALENGTH()的区别
    postMan测试https接口
    BigDecimal用法
  • 原文地址:https://www.cnblogs.com/ivorysi/p/10984481.html
Copyright © 2011-2022 走看看