当前位置:网站首页>暑假第一周
暑假第一周
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;
}边栏推荐
- Soem EtherCAT source code analysis attachment 1 (establishment of communication operation environment)
- STM32 outputs 1PPS with adjustable phase
- Sizeof (function name) =?
- MHA High available Cluster for MySQL
- 实例005:三数排序 输入三个整数x,y,z,请把这三个数由小到大输出。
- STM32 virtualization environment of QEMU
- Soem EtherCAT source code analysis II (list of known configuration information)
- 猜谜语啦(6)
- Imx6ull bare metal development learning 1-assembly lit LED
- Detailed summary of FIO test hard disk performance parameters and examples (with source code)
猜你喜欢

On boost circuit

猜谜语啦(9)

每日一题——替换空格

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?

Count the number of inputs (C language)

OC and OD gate circuit

Management and use of DokuWiki (supplementary)

Ble encryption details

Several implementation schemes of anti reverse connection protection of positive and negative poles of power supply!

Let's briefly talk about the chips commonly used in mobile phones - OVP chips
随机推荐
每日一题——替换空格
Speech recognition learning summary
OC and OD gate circuit
亿学学堂给的证券账户安不安全?哪里可以开户
One question per day - replace spaces
Tailq of linked list
Keil use details -- magic wand
Shell script realizes the reading of serial port and the parsing of message
第十八章 使用工作队列管理器(一)
Talk about the function of magnetic beads in circuits
STM32 virtualization environment of QEMU
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
Xrosstools tool installation for X-Series
2020-05-21
PIP installation
Ble encryption details
Void* C is a carrier for realizing polymorphism
[three tier architecture]
Arduino operation stm32
MATLAB小技巧(28)模糊綜合評價