当前位置:网站首页>暑假第一周
暑假第一周
2022-07-05 08:31:00 【Alex Su (*^▽^*)】
D. Infinite Set(二进制+dp)
关键是看成二进制,乘以4相当于补两个0,乘2加1相当于补一个1
dpi表示二进制表示长度为i的方案数,那么有dpi = dpi-1+dpi-2
那么考虑怎么处理已经有的数
首先要去掉一些重复的数,也就是一个数如果能被另一个数生成,就去掉
这个很好处理,就暴力枚举当前数可能由哪些数生成,然后用map看是否是已经有的数即可
那么用gi表示原本就已经有的数长度为i的有多少个
那么dpi = dpi + dpi-1 + gi
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define _for(i, a, b) for(int i = (a); i <= (b); i++)
using namespace std;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
int a[N], dp[N], g[N], n, p;
unordered_map<int, int> mp;
int len(int x)
{
int res = 0;
while(x) res++, x >>= 1;
return res;
}
bool check(int x)
{
while(x)
{
if(x % 4 == 0)
{
x /= 4;
if(mp[x]) return false;
}
else if((x - 1) % 2 == 0)
{
x = (x - 1) / 2;
if(mp[x]) return false;
}
else break;
}
return true;
}
int main()
{
scanf("%d%d", &n, &p);
_for(i, 1, n) scanf("%d", &a[i]), mp[a[i]] = 1;
_for(i, 1, n)
if(check(a[i]))
g[len(a[i])]++;
dp[1] = g[1];
_for(i, 2, p)
dp[i] = (dp[i - 1] + dp[i - 2] + g[i]) % mod;
int ans = 0;
_for(i, 1, p) ans = (ans + dp[i]) % mod;
printf("%d\n", ans);
return 0;
}边栏推荐
- Take you to understand the working principle of lithium battery protection board
- [three tier architecture and JDBC summary]
- Installation and use of libjpeg and ligpng
- 關於線性穩壓器的五個設計細節
- Example 007: copy data from one list to another list.
- Imx6ull bare metal development learning 2- use C language to light LED indicator
- go依赖注入--google开源库wire
- STM32---IIC
- STM32 --- NVIC interrupt
- 猜谜语啦(8)
猜你喜欢

MySQL之MHA高可用集群

On boost circuit
![[paper reading] the latest transfer ability in deep learning: a survey in 2022](/img/6b/b564fb7a6895329073fb5eaff64340.png)
[paper reading] the latest transfer ability in deep learning: a survey in 2022

Example 003: a complete square is an integer. It is a complete square after adding 100, and it is a complete square after adding 168. What is the number?

Shell script

Array integration initialization (C language)

List of linked lists

Management and use of DokuWiki (supplementary)

319. 灯泡开关

OC and OD gate circuit
随机推荐
Sizeof (function name) =?
Xrosstools tool installation for X-Series
Basic information commands and functions of kernel development
Example 003: a complete square is an integer. It is a complete square after adding 100, and it is a complete square after adding 168. What is the number?
实例007:copy 将一个列表的数据复制到另一个列表中。
STM32 --- GPIO configuration & GPIO related library functions
Buildroot system for making raspberry pie cm3
动力电池UL2580测试项目包括哪些
【NOI模拟赛】汁树(树形DP)
Several important parameters of LDO circuit design and type selection
C language data type replacement
Soem EtherCAT source code analysis attachment 1 (establishment of communication operation environment)
Daily question - input a date and output the day of the year
Example 009: pause output for one second
UE像素流,来颗“减肥药”吧!
Tailq of linked list
696. 计数二进制子串
Typical low code apaas manufacturer cases
Google sitemap files for rails Projects - Google sitemap files for rails projects
Example 001: the number combination has four numbers: 1, 2, 3, 4. How many three digits can be formed that are different from each other and have no duplicate numbers? How many are each?