题目链接: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$ 选出几个互不相交的爪形结构。

题解

衍生的过程是具有重复性的,最终变化的是根结点 $1$ 下的三棵子树,左右两棵子树为 $level_{n - 2}$,中间的子树为 $level_{n - 1}$ 。

因为 $level_1$ 和 $level_2$ 的根结点并未使用,所以可以在 $level_3$ 中选择以根结点 $1$ 为中心的爪形结构。

同理,$level_4$、$level_5$ 可以通过选取较下层的爪形结构来避免根结点的使用,所以在 $level_6$ 中又可以选取以根结点 $1$ 为中心的爪形结构。

即,$level$ 为 $3$ 的倍数的图形都可以再额外选取位于根结点的爪形结构。

综上,设 $dp_i$ 为 $level_i$ 中最多可选出的互不相交的爪形结构个数,有递推式:

\begin{equation} dp_i = 2 \times dp_{i - 2} + dp_{i - 1} + (i\ \%\ 3 == 0) \end{equation}

代码

#include <bits/stdc++.h>
using namespace std;
constexpr int N = 2e6 + 10;
constexpr int mod = 1e9 + 7; int dp[N]; void init() {
dp[1] = dp[2] = 0;
dp[3] = dp[4] = 1;
for (int i = 5; i < N; i++)
dp[i] = (2LL * dp[i - 2] + dp[i - 1] + (i % 3 == 0)) % mod;
} void solve() {
int n; cin >> n;
cout << 4LL * dp[n] % mod << "\n";
} int main() {
init();
int t; cin >> t;
while (t--) solve();
}

Codeforces Round #652 (Div. 2) D. TediousLee(dp)的更多相关文章

  1. Codeforces Round #260 (Div. 2)C. Boredom(dp)

    C. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  2. Codeforces Round #652 (Div. 2) C. RationalLee(贪心)

    题目链接:https://codeforces.com/contest/1369/problem/C 题意 将 $n$ 个数分给 $k$ 个人,每个人分 $w_i$ 个数($\sum_{i = 1}^ ...

  3. Codeforces Round #652 (Div. 2) E. DeadLee(贪心)

    题目链接:https://codeforces.com/contest/1369/problem/E 题意 Lee 有 $n$ 种不同种类的食物和 $m$ 个朋友,每种食物有 $w_i$ 个,每个朋友 ...

  4. Codeforces Round #652 (Div. 2) B. AccurateLee(字符串)

    题目链接:https://codeforces.com/contest/1369/problem/B 题意 给出一个长 $n$ 的 二进制串,每次可以选择字符串中的一个 $10$,然后删除其中的一个字 ...

  5. Codeforces Round #652 (Div. 2) A. FashionabLee(几何)

    题目链接:https://codeforces.com/contest/1369/problem/A 题意 判断正 $n$ 边形能否通过旋转使得一边与 $x$ 轴平行,一边与 $y$ 轴平行. 题解 ...

  6. Codeforces Round #658 (Div. 2) D. Unmerge(dp)

    题目链接:https://codeforces.com/contest/1382/problem/D 题意 给出一个大小为 $2n$ 的排列,判断能否找到两个长为 $n$ 的子序列,使得二者归并排序后 ...

  7. Codeforces Round #471 (Div. 2) F. Heaps(dp)

    题意 给定一棵以 \(1\) 号点为根的树.若满足以下条件,则认为节点 \(p\) 处有一个 \(k\) 叉高度为 \(m\) 的堆: 若 \(m = 1\) ,则 \(p\) 本身就是一个 \(k\ ...

  8. 【Codeforces】Codeforces Round #374 (Div. 2) -- C. Journey (DP)

    C. Journey time limit per test3 seconds memory limit per test256 megabytes inputstandard input outpu ...

  9. Codeforces Round #247 (Div. 2) C. k-Tree (dp)

    题目链接 自己的dp, 不是很好,这道dp题是 完全自己做出来的,完全没看题解,还是有点进步,虽然这个dp题比较简单. 题意:一个k叉树, 每一个对应权值1-k, 问最后相加权值为n, 且最大值至少为 ...

随机推荐

  1. 如果生成allure报告过程中报错AttributeError: module 'allure' has no attribute 'severity_level'

    1.pip uninstall pytest-allure-adaptor 2.pip install allure-pytest 3.搞定 快去吃饭吧

  2. Vim 自动添加脚本头部信息

    每次写脚本还在为忘记添加头部信息啥的烦恼? 按照下面这么做,帮你减轻点烦恼. # 打开配置文件: vim /root/.vimrc # 添加如下信息: autocmd BufNewFile *.sh ...

  3. vim 手动添加脚本头部信息

    vim /root/.vimrc 8,1 全部 set autoindent set tabstop=5 set shiftwidth=4 function AddTitle() call setli ...

  4. 为了加快速度,Redis都做了哪些“变态”设计

    前言 列表对象是 Redis 中 5 种基础数据类型之一,在 Redis 3.2 版本之前,列表对象底层存储结构有两种:linkedlist(双端列表)和 ziplist(压缩列表),而在 Redis ...

  5. misc刷题

    前言:听说misc打得好,头发多不了 kali自带的字典: cd /usr/share/wordlists/ 字典网站:http://contest-2010.korelogic.com/wordli ...

  6. oracle rac搭建单实例DG步骤(阅读全篇后再做)

    环境介绍 主库: 主机名 rac01 rac02 实体IP 10.206.132.232 10.206.132.233 私有IP 192.168.56.12 192.168.56.13 虚拟IP 10 ...

  7. 边缘计算k8s集群SuperEdge初体验

    前言 手上一直都有一堆的学生主机,各种各样渠道途径拿来的机器. 一直管理里面都比较蛋疼,甚至也不太记得住它们在哪是什么IP,管理起来很是头疼. 有阵子空闲的时候想折腾了一下边缘计算集群方案. 希望能把 ...

  8. error: Failed dependencies: rpm安装包失败报错依赖包

    error: Failed dependencies: mysql-community-release conflicts with (installed) mysql57-community-rel ...

  9. 记一次Nginx反向代理500的排查记录

    今天公司项目遇到一个奇怪的问题,记录一下. 注: 数据已经过脱敏处理,未暴露公司具体的IP等数据. TLDR; 项目简单介绍 用 Vue + ElementUI 实现的后台项目(以下简称:a-proj ...

  10. 406 UDP协议是面向非连接的协议 Keep-Alive

    HTTP The Definitive Guide   Table 3-1. Common HTTP methods   Method Description Message body?   GET ...