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. 【强化学习】1-1-2 “探索”(Exploration)还是“ 利用”(Exploitation)都要“面向目标”(Goal-Direct)

    title: [强化学习]1-1-2 "探索"(Exploration)还是" 利用"(Exploitation)都要"面向目标"(Goal ...

  2. Java基础语法n

    BK      分段函数(SDUT 2257) import java.util.*; public class Main{ public static void main(String[] args ...

  3. Python爬虫 Urllib库的基本使用

    1.构造Requset 其实上面的urlopen参数可以传入一个request请求,它其实就是一个Request类的实例,构造时需要传入Url,Data等等的内容.比如上面的两行代码,我们可以这么改写 ...

  4. Java基础线程系列大纲

    ## Java 多线程之 线程创建 ## Java 多线程之 Sleep ## Java 多线程之 Join ## Java 多线程之 生命周期 ## Java 多线程之 wait, notify a ...

  5. 利用Apache shiro SimpleHash 加密字符串

    1.导入包 import org.apache.shiro.crypto.hash.SimpleHash; 1 2.代码 import org.apache.shiro.crypto.hash.Sim ...

  6. IntelliJ IDEA利用Maven下载所需的JAR包到项目中

    直接复制JetBrains/../conf/settings.xml后修改镜像出现问题,然后用了这里的settings.xml配置文件.

  7. UITableView动态改变Cell高度

    demo下载地址:https://github.com/smileyborg/TableViewCellWithAutoLayout 版权声明:本文为博主原创文章,未经博主允许不得转载.

  8. A*算法解决15数码问题_Python实现

    1问题描述 数码问题常被用来演示如何在状态空间中生成动作序列.一个典型的例子是15数码问题,它是由放在一个4×4的16宫格棋盘中的15个数码(1-15)构成,棋盘中的一个单元是空的,它的邻接单元中的数 ...

  9. C#可以直接调用的Win32API

    以前整理的Win32 API,可以直接在C#中直接调用,在做WinForm时还是很有帮助的.以前用在一个多窗口界面中,当轮询窗口时,调用API会提高很多效率. 源码下载 http://files.cn ...

  10. Spring+Ibatis开发

    Spring+Ibatis开发:1.首先回忆Spring+Hibernate开发:那么时候我们是先加入的Spring,然后在加入Hibernate支持包的,而此时我们Spring+Ibatis开发,原 ...