当前位置:网站首页>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;
}边栏推荐
- 每日一题——输入一个日期,输出它是该年的第几天
- Let's briefly talk about the chips commonly used in mobile phones - OVP chips
- 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
- [NAS1](2021CVPR)AttentiveNAS: Improving Neural Architecture Search via Attentive Sampling (未完)
- Meizu Bluetooth remote control temperature and humidity access homeassistant
- Naming rules for FreeRTOS
- 99 multiplication table (C language)
- Classic application of MOS transistor circuit design (2) - switch circuit design
- Talk about the function of magnetic beads in circuits
- QEMU STM32 vscode debugging environment configuration
猜你喜欢

FIO测试硬盘性能参数和实例详细总结(附源码)

剑指 Offer 05. 替换空格

实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.

猜谜语啦(2)

leetcode - 445. 两数相加 II

Business modeling of software model | object modeling

L298N module use

QEMU STM32 vscode debugging environment configuration

剑指 Offer 09. 用两个栈实现队列

STM32 lights up the 1.8-inch screen under Arduino IDE
随机推荐
Zero length array in GNU C
Shell script
Synchronization of QT multithreading
实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
【NOI模拟赛】汁树(树形DP)
MATLAB小技巧(28)模糊綜合評價
How apaas is applied in different organizational structures
STM32 outputs 1PPS with adjustable phase
Detailed summary of FIO test hard disk performance parameters and examples (with source code)
Esphone retrofits old fans
Meizu Bluetooth remote control temperature and humidity access homeassistant
Is the security account given by Yixue school safe? Where can I open an account
go依赖注入--google开源库wire
One question per day - replace spaces
Cinq détails de conception du régulateur de tension linéaire
实例004:这天第几天 输入某年某月某日,判断这一天是这一年的第几天?
List of linked lists
MHA High available Cluster for MySQL
猜谜语啦(5)
[noi simulation] juice tree (tree DP)