Contest Website : atcoder.jp/contests/dp

\[\begin{array}{c|C|c|c}
TaskNum & TaskName & Status & Algorithm \\
\hline
A & Frog 1 & \color{green}{AC} & \text{简单线性DP} \\
\hline
B & Frog 2 & \color{green}{AC} & \text{简单线性DP,TaskA加强版} \\
\hline
C & Vacation & \color{green}{AC} & \text{简单线性DP} \\
\hline
D & Knapsack 1 & \color{green}{AC} & \text{OI背包} \\
\hline
E & Knapsack 2 & \color{yellow}{WA} & \text{01背包重大价小} \\
\hline
F & LCS & \color{green}{AC} & \text{最长公共子序列} \\
\hline
G & Longest Path & \color{green}{AC} & \text{DAG上DP} \\
\hline
H & Grid 1 & \color{green}{AC} & \text{矩阵DP} \\
\hline
I & Coins & \color{green}{AC} & \text{概率DP} \\
\hline
J & Sushi & \color{green}{AC} & \text{期望DP} \\
\hline
K & Stones & \color{green}{AC} & \text{博弈论} \\
\hline
L & Deque & \color{green}{AC} & \text{区间DP} \\
\hline
M & Candies & \color{green}{AC} & \text{前缀和优化线性DP} \\
\hline
N & Slimes & \color{green}{AC} & \text{区间DP} \\
\hline
O & Matching & \color{green}{AC} & \text{状压DP} \\
\hline
P & Independent Set & \color{green}{AC} & \text{树形DP} \\
\hline
Q & Flowers & & \\
\hline
R & Walk & & \\
\hline
S & Digit Sum & & \\
\hline
T & Permutation & & \\
\hline
U & Grouping & & \\
\hline
V & Subtree & & \\
\hline
W & Intervals & & \\
\hline
X & Tower & & \\
\hline
Y & Grid 2 & & \\
\hline
Z & Frog 3 & & \\
\end{array}
\]

A. Frog 1

We define \(f_i\) as the minimum cost for the frog to jump from the 1st stone to the \(i\)-th stone.

And we know that the frog can only jump from the \((i-1)\)-th stone or the \((i-2)\)th stone to the \(i\)-th stone. Thus, we can know the equation. It is:

\[f_i=\operatorname{min}\{f_{i-1}+\left\vert h_i-h_{i-1} \right\vert ,f_{i-2}+\left\vert h_i-h_{i-2} \right\vert \}
\]

\(O(n)\) ~

B. Frog 2

\[f_{i+j}=\operatorname{min}\{f_i+\left\vert h_i-h_{i+j}\ \right\vert\},1\le j\le k
\]

Why don't I use \(f_{i-j}\) to transfer to \(f_i\)? That's because I don't want to check if \(i-j < 0\). I think this is an unimportant skill

\(O(nk)\)

C. Vacation

Easy~

We define \(f_{i,j}\) is the maximum points of happiness at Day i, and we choose activity j at Day i. We cannot choose activity j at Day i+1.

So, \(f_{i,j}\) can be transfered from \(f_{i-1,k}\, ,k\neq j\).

\[f_{i,1} = \operatorname{max}\{f_{i-1,2},f_{i-1,3}\} + a_i
\]
\[f_{i,2} = \operatorname{max}\{f_{i-1,1},f_{i-1,3}\} + b_i
\]
\[f_{i,3} = \operatorname{max}\{f_{i-1,1},f_{i-1,2}\} + c_i
\]

The answer is \(\operatorname{max}\{f_{n,1},f_{n,2},f_{n,3}\}\).

\(O(n)\) ~

D. Knapsack 1

01 backpack.

Because I cannot explain it in English, so I will only write the equation.

\(i\) is the i-th item, \(v\) refers to the remaining capacity.

\[f_{v}=\operatorname{max}\{f_v,f_{v-w_i}+c_i\}
\]

\(O(nw)\)

F. LCS

嘤语不会用了QAQ

定义 \(f_{i,j}\) 为 \(s\) 串前 \(i\) 个字符和 \(t\) 串前 \(j\) 个字符的LCS。

\[f_{i,j}=\begin{cases}
f_{i-1,j-1}+1, & s_i=t_j \\
\operatorname{max}\{f_{i-1,j},f_{i,j-1}\}, &\text{otherwise}
\end{cases} \]

\(O(n^2)\)

G. Longest Path

We have two methods to solve this task.

First, we use Topological sorting. Then, we can traverse the topological order from back to front.

Second, we can use the memorizing search method.

\[f_{i}=\operatorname{max}\{f_{j}+1\}
\]

\(O(n+m)\)

H. Grid 1

Matrix DP.

We can walk to the right and the bottom point.

So, we can walk from the left and the top point.

\[f_{i,j}=f_{i-1,j}+f{i,j-1}
\]

\(O(HW)\)

I. Coins

Probability DP.

We define f[i][j] is the probability of \(j\) out of the first \(i\) coins turned heads.

So, if we need \(j\) coins turns heads, we have \(2\) options.

  1. There are \(j\) out of the first \(i - 1\) coins turned heads and the i-th coin flip to the back.
  2. There are \(j - 1\) out of the first \(i - 1\) coins turned heads and the i-th coin turn to the front.
\[f_{i,j}=f_{i-1,j} * (1-p_i) + f_{i-1,j-1}*p_i
\]

\(O(n^2)\)

J. Sushi

求期望。

设 \(f_{i,j,k}\) 为还剩 \(i\) 个盘子有一个寿司,\(j\) 个盘子有两个寿司,\(k\) 个盘子有三个寿司时的期望值。

方程不会写。

\(O(n^3)\)

K. Stones

Game theory.

If there left \(k\) stones left and this state can win, then there must a state of \(f\) that \(k-a_i=f\) and this state must lose.

\[f_{i} = 1, f_{i - a_j} = 0\; and\;1 \le j \le n
\]

L. Deque

The first type of Range DP.

We define \(f_{i,j}\) as the maximum value the first people can get in the range \([i,j]\).

So, \(f_{i,j}\) can be translated from \(f_{i+1,j}\) and \(f_{i,j-1}\).

\[f_{i,j}=\sum_{i-1}^{j} a_i - \operatorname{min}\{f_{i+1,j},f_{i,j-1}\}
\]

\(O(n^2)\)

M. Candies

Prefix Sum Optimization.

First, we all know that

\[f_{i,j}=\sum_{k=j-a_i}^{j} f_{i,k}
\]

But the time complexity of this algorithm is \(O(nk^2)\), So we cannot pass this task with this algo.

So we need Prefix Sum Optimization. We define \(pre_{m}\) as \(\sum_{k=1}^{m}f_{i,k}\).

\[f_{i,j}=pre_j-pre_{j-a_i-1}
\]

Sth about Educational DP Contest的更多相关文章

  1. Atcoder Educational DP Contest

    前面简单一点的题直接过吧. A 暴力DP B 怎么还是暴力DP C 还是暴力DP D 直接背包 E 这个背包不太一样了,这里有一个技巧,就是因为价值很小,所以直接对价值背包,求出来达到某一个权值最小的 ...

  2. Atcoder Educational DP Contest 题解

    A - Frog 1/B - Frog 2 入门... #include<cstdio> #define abs(a) ((a)>=0?(a):(-(a))) #define min ...

  3. Atcoder Educational DP Contest I - Coins (概率DP)

    题意:有\(n\)枚硬币,每枚硬币抛完后向上的概率为\(p[i]\),现在求抛完后向上的硬币个数大于向下的概率. 题解:我们用二维的\(dp[i][j]\)来表示状态,\(i\)表示当前抛的是第\(i ...

  4. Educational DP Contest H - Grid 1 (DP)

    题意:有一个\(n\)X\(m\)的图,"#"表示障碍物,"."表示道路,只能向右或向下走,问从左上角走到右下角的方案数. 题解:这题可以用bfs来搞,但dp更 ...

  5. Educational DP Contest G - Longest Path (dp,拓扑排序)

    题意:给你一张DAG,求图中的最长路径. 题解:用拓扑排序一个点一个点的拿掉,然后dp记录步数即可. 代码: int n,m; int a,b; vector<int> v[N]; int ...

  6. Educational DP Contest F - LCS (LCS输出路径)

    题意:有两个字符串,求他们的最长公共子序列并输出. 题解:首先跑个LCS记录一下dp数组,然后根据dp数组来反着还原路径,只有当两个位置的字符相同时才输出. 代码: char s[N],t[N]; i ...

  7. Educational DP Contest E - Knapsack 2 (01背包进阶版)

    题意:有\(n\)个物品,第\(i\)个物品价值\(v_{i}\),体积为\(w_{i}\),你有容量为\(W\)的背包,求能放物品的最大价值. 题解:经典01背包,但是物品的最大体积给到了\(10^ ...

  8. 【DP】Educational DP Contest

    这份 dp 题单的最后几题好难 orz. 前面的题比较简单,所以我会选取一些题来讲,其它的直接看代码理解吧 qwq. 传送门: https://atcoder.jp/contests/dp 全部 AC ...

  9. AtCoder Educational DP Contest 总结

    前言 感觉都初一升初二了,再做这个题是不是有点太菜了啊-- 里面大概都是些 DP 板子题(确信,题目质量还挺高的,不过不涉及太难的优化(实际上只有最后一题是斜率优化). 不管了,还是写个 blog 来 ...

随机推荐

  1. Vue项目的开发流程

    我先安装的node.js 1.确认已安装了node.js,可在cmd中输入( node -v和npm -v),如显示出版号,说明安装成功 2.安装webpack 和webpack-cli 在全局下安装 ...

  2. NAT介绍与配置

    一,NAT定义 二.NAT的分类 三,NAT配置实验 一,NAT定义 NAT(Network Address Translation),网络地址转换技术,随着Internet的发展,IPv4地址枯竭已 ...

  3. 12、关于系统cpu的计算

    1.cpu核数和逻辑cpu: CPU总核数 = 物理CPU个数 * 每颗物理CPU的核数: 总逻辑CPU数 = 物理CPU个数 * 每颗物理CPU的核数 * 超线程数 2.查看linux的cpu相关信 ...

  4. 21、部署heartbeat

    21.1.heartbeat部署规划: 本文的实验环境是虚拟机设备: 名称 接口 ip 用途 master-db(主) eth0 10.0.0.16/24 用于服务器之间的心跳连接(直连) eth1 ...

  5. 从三道题目入门frida

    偶然从看雪看到了一篇入门frida的题目,正好苦于没练手的东西,直接上手一波 1.第一题jadx打开,也没有壳和混淆,整体非常清晰,判断的逻辑也很简单 发现其实就是两个输入框,一个用户名一个密码,先拼 ...

  6. shell运维习题训练

    注:初学shell,以下为本人自己写的答案,如果有更好的,请指教! 1. 求2个数之和: 2. 计算1-100的和 3. 将一目录下所有的文件的扩展名改为bak 4.编译并执行当前目录下的所有.c文件 ...

  7. STM32笔记一

    1.脉冲宽度调制是(PWM):用微处理器的数字输出来对模拟电路进行控制的一种非常有效的技术,广泛应用在从测量.通信到功率控制与变换的许多领域中.一般用于直流电机调速. 2.外部中断:外部中断是单片机实 ...

  8. 『心善渊』Selenium3.0基础 — 29、使用HTMLTestRunner生成unittest的HTML报告

    目录 1.HTMLTestRunner介绍 2.HTMLTestRunner的使用 3.测试报告示例 4.封装成模块 1.HTMLTestRunner介绍 HTMLTestRunner是一个基于uni ...

  9. homestead

    前言 之前写过一篇文章(https://www.jianshu.com/p/5f30280a3c18),说不需要这玩意儿一样可以开发.是的,但是对于团队来说,使用统一的环境.开发工具.编码规范等,对于 ...

  10. 获取操作系统OS等相关信息

    问题一:Windows SDK 8.1版本中的VersionHelper.h文件当中没有IsWindows10ORGreater,所以当你用IsWindows8Point1ORGreater判断出版本 ...