Cut Ribbon time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions: After the…
C. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a ga…
题目链接:https://codeforces.com/contest/1382/problem/D 题意 给出一个大小为 $2n$ 的排列,判断能否找到两个长为 $n$ 的子序列,使得二者归并排序后能够得到该排列. 题解 将原排列拆分为一个个连续子序列,每次从大于上一子序列首部的元素处分出下一连续子序列,只要将这些子序列按照拆分先后排列,归并排序后一定可以得到原排列. 之后即判断能否将这些子序列排列为两个长为 $n$ 的序列即可,可以用状压 $dp$,也可以用 $01$ 背包. 状态 $dp$…
题意 给定一棵以 \(1\) 号点为根的树.若满足以下条件,则认为节点 \(p\) 处有一个 \(k\) 叉高度为 \(m\) 的堆: 若 \(m = 1\) ,则 \(p\) 本身就是一个 \(k\) 叉高度为 \(1\) 的堆. 若 \(m > 1\) ,则 \(p\) 需要有至少 \(k\) 个儿子满足在儿子处有一个 \(k\) 叉高度为 \(m − 1\) 的堆. 令 \(dp[p][k]\) 表示在 \(p\) 点 \(k\) 叉堆的最大高度,令 \(g[p][k]\) 为 \(p\)…
C. Journey time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are n showplaces to n, and some of them…
题目链接:https://codeforces.com/contest/1369/problem/D 题意 最初有一个结点,衍生规则如下: 如果结点 $u$ 没有子结点,添加 $1$ 个子结点 如果结点 $u$ 有 $1$ 个子结点,添加 $2$ 个子结点 如果结点 $u$ 有 $3$ 个子结点,跳过该结点 如: \begin{equation} level = 1, 2, 3,4 \end{equation} 爪形结构如下: 问可以在 $level_n$ 选出几个互不相交的爪形结构. 题解 衍…
题目链接 自己的dp, 不是很好,这道dp题是 完全自己做出来的,完全没看题解,还是有点进步,虽然这个dp题比较简单. 题意:一个k叉树, 每一个对应权值1-k, 问最后相加权值为n, 且最大值至少为d 的路径有多少条. 思路:d[i][l][sum] 表示第i 行最大值为l, 总和为sum的路径数. 注意:我的代码中 sum + j 有可能会超过数组最大值,即越界,刚开始我以为不会产生影响,后来 发现不知道为什么 在数组里越界以后比如 越界到d[][][111] 会对 d[][][1]产生影响…
Greenhouse Effect time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length. Over th…
Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities. To bake…
题目链接:http://codeforces.com/problemset/problem/460/C C. Present time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little beaver is a beginner programmer, so informatics is his favorite subjec…