当前位置:网站首页>The first week of summer vacation
The first week of summer vacation
2022-07-05 08:33:00 【Alex Su (*^▽^*)】
D. Infinite Set( Binary system +dp)
The key is to look at binary , multiply 4 Equivalent to two 0, ride 2 Add 1 It's equivalent to adding one 1
dpi Indicates that the binary indicates that the length is i Number of alternatives , So there are dpi = dpi-1+dpi-2
Then consider how to deal with the existing numbers
First, remove some duplicate numbers , That is, if one number can be generated by another number , Just remove
This is very easy to handle , Enumerate which numbers the current number may be generated by , And then use map See if it's the number you already have
Then use gi It means that the length of the existing number is i How many
that 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;
}边栏推荐
- [NAS1](2021CVPR)AttentiveNAS: Improving Neural Architecture Search via Attentive Sampling (未完)
- Ble encryption details
- Sword finger offer 06 Print linked list from end to end
- Management and use of DokuWiki (supplementary)
- Business modeling of software model | object modeling
- Example 006: Fibonacci series
- 2020-05-21
- Talk about the function of magnetic beads in circuits
- 猜谜语啦(4)
- 猜谜语啦(9)
猜你喜欢

MHA High available Cluster for MySQL

Arduino+a4988 control stepper motor

猜谜语啦(142)

Bluebridge cup internet of things competition basic graphic tutorial - clock selection

MySQL MHA high availability cluster

STM32 single chip microcomputer - bit band operation

Simple design description of MIC circuit of ECM mobile phone

STM32 single chip microcomputer - external interrupt

猜谜语啦(3)

Xrosstools tool installation for X-Series
随机推荐
Example 005: three numbers sorting input three integers x, y, Z, please output these three numbers from small to large.
实例010:给人看的时间
STM32---IIC
Slist of linked list
Circleq of linked list
On boost circuit
Is the security account given by Yixue school safe? Where can I open an account
287. 寻找重复数-快慢指针
More than 90% of hardware engineers will encounter problems when MOS tubes are burned out!
实例005:三数排序 输入三个整数x,y,z,请把这三个数由小到大输出。
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
Lori remote control LEGO motor
Example 006: Fibonacci series
Arduino operation stm32
Cmder of win artifact
Talk about the circuit use of TVs tube
实例007:copy 将一个列表的数据复制到另一个列表中。
Charge pump boost principle - this article will give you a simple understanding
猜谜语啦(5)
Stm32--- systick timer