LibreOJ #507. 「LibreOJ NOI Round #1」接竹竿
二次联通门 : LibreOJ #507. 「LibreOJ NOI Round #1」接竹竿
/*
LibreOJ #507. 「LibreOJ NOI Round #1」接竹竿 dp
记录一下前驱就好了
再随便用前缀和优化一下
O(N) */
#include <iostream>
#include <cstdio> const int BUF = ;
char Buf[BUF], *buf = Buf; inline long long max (long long a, long long b)
{
return a > b ? a : b;
} void read (int &now)
{
for (now = ; !isdigit (*buf); ++ buf);
for (; isdigit (*buf); now = now * + *buf - '', ++ buf);
} #define Max 1000020
int N, K;
long long sum[Max]; int to[Max];
int last_kind[Max * ]; long long dp[Max]; int main (int argc, char *argv[])
{
fread (buf, , BUF, stdin);
read (N);
read (K); register int i;
int x;
for (i = ; i <= N; ++ i)
{
read (x);
to[i] = last_kind[x];
last_kind[x] = i;
} for (i = ; i <= N; ++ i)
{
read (x);
sum[i] = sum[i - ] + x;
} register int res;
for (i = ; i <= N; ++ i)
{
dp[i] = dp[i - ];
if (to[i])
dp[i] = max (dp[i], max (dp[to[i]] + sum[i] - sum[to[i]], dp[to[i] - ] + sum[i] - sum[to[i] - ]));
} printf ("%lld", dp[N]);
return ;
}
LibreOJ #507. 「LibreOJ NOI Round #1」接竹竿的更多相关文章
- #507. 「LibreOJ NOI Round #1」接竹竿 dp
题目: 题解: 我们考虑把每对花色相同的牌看作区间. 那么如果我们设 \(f_i\) 表示决策在 \([1,i]\) 内的最优答案. 那么有 \(f_i = max\{max\{(f_{j-1}+\s ...
- 「LibreOJ NOI Round #2」不等关系
「LibreOJ NOI Round #2」不等关系 解题思路 令 \(F(k)\) 为恰好有 \(k\) 个大于号不满足的答案,\(G(k)\) 表示钦点了 \(k\) 个大于号不满足,剩下随便填的 ...
- LibreOJ #517. 「LibreOJ β Round #2」计算几何瞎暴力
二次联通门 : LibreOJ #517. 「LibreOJ β Round #2」计算几何瞎暴力 /* LibreOJ #517. 「LibreOJ β Round #2」计算几何瞎暴力 叫做计算几 ...
- LibreOJ #528. 「LibreOJ β Round #4」求和
二次联通门 : LibreOJ #528. 「LibreOJ β Round #4」求和 /* LibreOJ #528. 「LibreOJ β Round #4」求和 题目要求的是有多少对数满足他们 ...
- LibreOJ #527. 「LibreOJ β Round #4」框架
二次联通门 : LibreOJ #527. 「LibreOJ β Round #4」框架 /* LibreOJ #527. 「LibreOJ β Round #4」框架 %% xxy dalao 对于 ...
- LibreOJ #526. 「LibreOJ β Round #4」子集
二次联通门 : LibreOJ #526. 「LibreOJ β Round #4」子集 /* LibreOJ #526. 「LibreOJ β Round #4」子集 考虑一下,若两个数奇偶性相同 ...
- LibreOJ #525. 「LibreOJ β Round #4」多项式
二次联通门 : LibreOJ #525. 「LibreOJ β Round #4」多项式 官方题解 : /* LibreOJ #525. 「LibreOJ β Round #4」多项式 由于会有多种 ...
- LibreOJ #524. 「LibreOJ β Round #4」游戏
二次联通门 : LibreOJ #524. 「LibreOJ β Round #4」游戏 /* LibreOJ #524. 「LibreOJ β Round #4」游戏 找找规律就会发现.. 当有X的 ...
- LibreOJ #516. 「LibreOJ β Round #2」DP 一般看规律
二次联通门 : LibreOJ #516. 「LibreOJ β Round #2」DP 一般看规律 /* LibreOJ #516. 「LibreOJ β Round #2」DP 一般看规律 set ...
随机推荐
- PB数据窗口分页
第一步:增加一个计算列,此计算列必须放在Detail段,Expression中输入: ceiling(getrow()/500) --这里500还可以用全局函数取代,这样可以允许用户任意设置每页多少 ...
- linux查看系统未被挂载的磁盘空间的方法
原文URL:https://www.cnblogs.com/lemon-flm/p/7597403.html 解决AWS 挂载.解决挂载完重启就消失等问题 linux上的盘和window的有区别,磁盘 ...
- 运输计划[二分答案 LCA 树上差分]
也许更好的阅读体验 \(\mathcal{Description}\) 原题链接 概括一下题意 给一颗有\(n\)个点带边权的树,有\(m\)个询问,每次询问\(u,v\)两点间的权值和,你可以将树中 ...
- 第二次用map23333
度熊所居住的 D 国,是一个完全尊重人权的国度.以至于这个国家的所有人命名自己的名字都非常奇怪.一个人的名字由若干个字符组成,同样的,这些字符的全排列的结果中的每一个字符串,也都是这个人的名字.例如, ...
- MySQL多表关联查询数量
//多表关联查询数量select user, t1.count1, t2.count2from user tleft join ( select user_id, count(sport_type) ...
- WinForm 无焦点获取键盘输入
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- FreeRTOS 任务创建和删除(动态)
TaskHandle_t taskhandle; TaskHandle_t taskhandle1; void vTask(void *t) { int i = 0; while(1) { i++; ...
- Mac命令行指定特定程序打开文件
如果文件已被指定默认程序 open httpd.conf 指定一个特定程序打开文件 # 用 sublime text 打开 httpd.conf open -a /Applications/Subli ...
- nginx 默认配置语法和日志的format
nginx 默认配置 查看有nginx哪些默认配置文件,打开/etc/nginx/nginx.conf文件,查看尾行部分 会默认将/etc/nginx/conf.d/文件下其他以.conf结尾的配置文 ...
- Keras实现Hierarchical Attention Network时的一些坑
Reshape 对于的张量x,x.shape=(a, b, c, d)的情况 若调用keras.layer.Reshape(target_shape=(-1, c, d)), 处理后的张量形状为(?, ...