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('\n')
#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();
}

【LOJ】#3092. 「BJOI2019」排兵布阵的更多相关文章

  1. LOJ 3092 「BJOI2019」排兵布阵 ——DP

    题目:https://loj.ac/problem/3092 同一个人的不同城堡之间没有什么联系,只是和<=m.所以对每个城堡的 s 个值排序,做一个 f[ i ][ j ] 表示第 i 个城堡 ...

  2. LOJ#3092. 「BJOI2019」排兵布阵(递推)

    题面 传送门 题解 设\(dp_{i,j}\)表示前\(i\)座塔派了总共\(j\)个人的最大收益,转移显然 //minamoto #include<bits/stdc++.h> #def ...

  3. Loj #3093. 「BJOI2019」光线

    Loj #3093. 「BJOI2019」光线 题目描述 当一束光打到一层玻璃上时,有一定比例的光会穿过这层玻璃,一定比例的光会被反射回去,剩下的光被玻璃吸收. 设对于任意 \(x\),有 \(x\t ...

  4. Loj #3089. 「BJOI2019」奥术神杖

    Loj #3089. 「BJOI2019」奥术神杖 题目描述 Bezorath 大陆抵抗地灾军团入侵的战争进入了僵持的阶段,世世代代生活在 Bezorath 这片大陆的精灵们开始寻找远古时代诸神遗留的 ...

  5. loj 3090 「BJOI2019」勘破神机 - 数学

    题目传送门 传送门 题目大意 设$F_{n}$表示用$1\times 2$的骨牌填$2\times n$的网格的方案数,设$G_{n}$$表示用$1\times 2$的骨牌填$3\times n$的网 ...

  6. LOJ 3089 「BJOI2019」奥术神杖——AC自动机DP+0/1分数规划

    题目:https://loj.ac/problem/3089 没想到把根号之类的求对数变成算数平均值.写了个只能得15分的暴力. #include<cstdio> #include< ...

  7. LOJ 3094 「BJOI2019」删数——角标偏移的线段树

    题目:https://loj.ac/problem/3094 弱化版是 AGC017C . 用线段树维护那个题里的序列即可. 对应关系大概是: 真实值的范围是 [ 1-m , n+m ] :考虑设偏移 ...

  8. LOJ 3090 「BJOI2019」勘破神机——斯特林数+递推式求通项+扩域

    题目:https://loj.ac/problem/3090 题解:https://www.luogu.org/blog/rqy/solution-p5320 1.用斯特林数把下降幂化为普通的幂次求和 ...

  9. LOJ 3093 「BJOI2019」光线——数学+思路

    题目:https://loj.ac/problem/3093 考虑经过种种反射,最终射下去的光线总和.往下的光线就是这个总和 * a[ i ] . 比如只有两层的话,设射到第二层的光线是 lst ,那 ...

随机推荐

  1. c语言if-else的效率比较

    闲着没事测试下if-else的执行效率 测试环境:Mac pro i7 2.3Ghz ...编译器gcc 4.9,代码没有进行优化-O0: 测试代码:c代码1: int main(){ int n=1 ...

  2. 数学函数(C/C++)

    C中包含头文件<math.h> C++包含头文件<cmath> 函数 double cos(double) 该函数返回弧度角(double型)的余弦 double tan(do ...

  3. nginx 实现高并发和高负载

    一.Nginx是如何实现高并发的 service nginx start之后,然后输入#ps -ef|grep nginx,会发现Nginx有一个master进程和若干个worker进程,这些work ...

  4. lavarel数据库查找别名操作

    lavarel数据库查找别名操作 一.总结 一句话总结: 当有表前缀的时候:DB::table('users as table1')->select(DB::raw('table1.id'))- ...

  5. arcgis python desc.dataType

    desc = arcpy.Describe(r"C:\Users\dell\Documents\ArcGIS\ddd.shp") 是ShapeFile desc = arcpy.D ...

  6. Flutter移动电商实战 --(2)建立项目和编写入口文件

    1.创建项目 采用AndroidStudio构建本项目,FIle>New>New Flutter Project… 创建后的项目如下图所示: 我们着重需要注意一下几个文件夹,其他的暂时不用 ...

  7. 性能分析 | JVM发生内存溢出的8种原因及解决办法

    推荐阅读:史上最详细JVM与性能优化知识点综合整理 1.Java 堆空间 2.GC 开销超过限制 3.请求的数组大小超过虚拟机限制 4.Perm gen 空间 5.Metaspace 6.无法新建本机 ...

  8. LC 794. Valid Tic-Tac-Toe State

    A Tic-Tac-Toe board is given as a string array board. Return True if and only if it is possible to r ...

  9. LC 957. Prison Cells After N Days

    There are 8 prison cells in a row, and each cell is either occupied or vacant. Each day, whether the ...

  10. 使用Python爬取mobi格式电纸书

    最近做了个微信推送kindle电子书的公众号:kindle免费书库 不过目前电子书不算非常多,所以需要使用爬虫来获取足够书籍. 于是,写了以下这个爬虫,来爬取kindle114的电子书. 值得注意的地 ...