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. 【csp模拟赛2】 序列操作

    线性推,开数组太麻烦,可以用指针 代码: #include <iostream> #include <cstdio> #include <queue> using ...

  2. node中的koa2

    创建koa2工程 首先,我们创建一个目录hello-koa并作为工程目录用VS Code打开.然后,我们创建app.js,输入以下代码: // 导入koa,和koa 1.x不同,在koa2中,我们导入 ...

  3. windows 安装python2.7

    下载:https://www.python.org/downloads/release/python-2716/ 安装即可. 设置环境变量 进入C:\Python27,修改python.exe 为py ...

  4. Codeforces 915E. Physical Education Lessons(动态开点线段树)

    E. Physical Education Lessons 题目:一段长度为n的区间初始全为1,每次成段赋值0或1,求每次操作后的区间总和.(n<=1e9,q<=3e5) 题意:用线段树做 ...

  5. JavaWeb_(Spring框架)SpringAOP面向切面编程

    SpringAOP:面向切面编程(面向fifter编程) 通俗易懂术语:所有纵向重复的代码,我们提取成横向的代码 以下文章内容参考知乎:从0带你学习SpringAOP,彻底的理解AOP思想 传送门 1 ...

  6. conda虚拟环境 相关操作

    查询环境 conda env list 或者 conda info --envs 创建环境 conda create -n your_env_name python=3.7 删除环境 conda re ...

  7. 【Redis 向Redis中批量导入mysql中的数据(亲自测试)】

    转自:https://blog.csdn.net/kenianni/article/details/84910638 有改动,仅供个人学习 问题提出:缓存的冷启动问题 应用系统新版本上线,这时候 re ...

  8. async for 在爬虫中的使用例子

    import asyncio import re import typing from concurrent.futures import Executor, ThreadPoolExecutor f ...

  9. HashMap简单介绍

    哈希表(hash table)也叫散列表,是一种非常重要的数据结构,应用场景及其丰富,许多缓存技术(比如memcached)的核心其实就是在内存中维护一张大的哈希表. 一.什么是哈希表 在讨论哈希表之 ...

  10. mysql zip方式安装

    下载zip文件解压到安装目录,此时是没有data文件夹和my.ini文件的. 1.首先自己新建my.ini,内容如下: [client] port=3306 default-character-set ...