#P3226. [HNOI2012] 集合选数

    ID: 2275 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp2012湖南状态压缩,状压构造

[HNOI2012] 集合选数

Description

The course "Set Theory and Graph Theory" has a homework problem asking students to find all subsets of {1,2,3,4,5}\{1, 2, 3, 4, 5\} that satisfy the following condition: if xx is in the subset, then 2x2x and 3x3x cannot be in the subset.

Students do not like such enumeration-style problems, so they turned it into the following question: for any positive integer n(1n105)n\,(1\leq n\leq 10^5), how many subsets of {1,2,,n}\{1,2,\dots,n\} satisfy the above constraint (you only need to output the result modulo 109+110^9+1). Now this task is handed to you.

Input Format

A single line containing a positive integer nn.

Output Format

Output a single positive integer, the number of subsets of {1,2,,n}\{1,2,\dots,n\} that satisfy the above constraint.

4
8

Hint

Sample explanation:
There are 88 sets that meet the requirement, namely \varnothing, {1}\{1\}, {1,4}\{1,4\}, {2}\{2\}, {2,3}\{2,3\}, {3}\{3\}, {3,4}\{3,4\}, and {4}\{4\}.

Constraints:
For 30%30\% of the testdata, 1n201 \le n \le 20.
For 100%100\% of the testdata, 1n1051 \le n \le 10^5.

Translated by ChatGPT 5