当前位置:网站首页>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;
}
边栏推荐
- Talk about the function of magnetic beads in circuits
- Array integration initialization (C language)
- 实例004:这天第几天 输入某年某月某日,判断这一天是这一年的第几天?
- go依赖注入--google开源库wire
- Problem solving: interpreter error: no file or directory
- 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?
- Google sitemap files for rails Projects - Google sitemap files for rails projects
- STM32 --- configuration of external interrupt
- Arduino burning program and Arduino burning bootloader
- 猜谜语啦(5)
猜你喜欢
Brief discussion on Buck buck circuit
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?
STM32 single chip microcomputer - external interrupt
[nas1] (2021cvpr) attentivenas: improving neural architecture search via attentive sampling (unfinished)
Example 009: pause output for one second
猜谜语啦(9)
STM32 --- serial port communication
【三层架构及JDBC总结】
实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
How to copy formatted notepad++ text?
随机推荐
Summary of SIM card circuit knowledge
Arduino burning program and Arduino burning bootloader
关于线性稳压器的五个设计细节
STM32 --- GPIO configuration & GPIO related library functions
亿学学堂给的证券账户安不安全?哪里可以开户
Detailed summary of FIO test hard disk performance parameters and examples (with source code)
Esphone Feixun DC1 soft change access homeassstant
Xrosstools tool installation for X-Series
Classic application of MOS transistor circuit design (2) - switch circuit design
STM32 --- NVIC interrupt
猜谜语啦(9)
go依赖注入--google开源库wire
Apaas platform of TOP10 abroad
Arduino+a4988 control stepper motor
Low code platform | apaas platform construction analysis
[cloud native | learn kubernetes from scratch] III. kubernetes cluster management tool kubectl
Classic application of MOS transistor circuit design (1) -iic bidirectional level shift
Run菜单解析
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
Affected tree (tree DP)