当前位置:网站首页>暑假第一周
暑假第一周
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;
}
边栏推荐
- leetcode - 445. Add two numbers II
- Count the number of inputs (C language)
- Bluebridge cup internet of things basic graphic tutorial - GPIO input key control LD5 on and off
- 猜谜语啦(8)
- leetcode - 445. 两数相加 II
- Design a clock frequency division circuit that can be switched arbitrarily
- FIO测试硬盘性能参数和实例详细总结(附源码)
- Esp8266 interrupt configuration
- STM32 outputs 1PPS with adjustable phase
- DCDC circuit - function of bootstrap capacitor
猜你喜欢
【NOI模拟赛】汁树(树形DP)
DCDC circuit - function of bootstrap capacitor
STM32 single chip microcomputer - external interrupt
Charge pump boost principle - this article will give you a simple understanding
STM32---ADC
MySQL之MHA高可用集群
MySQL之MHA高可用集群
Daily question - input a date and output the day of the year
Briefly talk about the identification protocol of mobile port -bc1.2
Bluebridge cup internet of things competition basic graphic tutorial - clock selection
随机推荐
Example 002: the bonus paid by the "individual income tax calculation" enterprise is based on the profit commission. When the profit (I) is less than or equal to 100000 yuan, the bonus can be increase
Sword finger offer 09 Implementing queues with two stacks
List of linked lists
Is the security account given by Yixue school safe? Where can I open an account
Arduino+a4988 control stepper motor
FIO测试硬盘性能参数和实例详细总结(附源码)
MySQL之MHA高可用集群
Arrangement of some library files
猜谜语啦(11)
Array integration initialization (C language)
Take you to understand the working principle of lithium battery protection board
STM32 lights up the 1.8-inch screen under Arduino IDE
Low code platform | apaas platform construction analysis
QEMU demo makefile analysis
STM32---ADC
第十八章 使用工作队列管理器(一)
STM32 summary (HAL Library) - DHT11 temperature sensor (intelligent safety assisted driving system)
Stm32--- systick timer
STM32 single chip microcomputer -- volatile keyword
C language data type replacement