当前位置:网站首页>暑假第一周
暑假第一周
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;
}
边栏推荐
- Charge pump boost principle - this article will give you a simple understanding
- STM32 --- GPIO configuration & GPIO related library functions
- Daily question - input a date and output the day of the year
- Ble encryption details
- Explain task scheduling based on Cortex-M3 in detail (Part 2)
- leetcode - 445. Add two numbers II
- List of linked lists
- UE pixel stream, come to a "diet pill"!
- 实例001:数字组合 有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?
- STM32 single chip microcomputer - external interrupt
猜你喜欢
Negative pressure generation of buck-boost circuit
Several important parameters of LDO circuit design and type selection
实例005:三数排序 输入三个整数x,y,z,请把这三个数由小到大输出。
实例010:给人看的时间
Charge pump boost principle - this article will give you a simple understanding
Array integration initialization (C language)
Apaas platform of TOP10 abroad
Circleq of linked list
MySQL之MHA高可用集群
Sword finger offer 06 Print linked list from end to end
随机推荐
Stm32--- systick timer
Example 010: time to show
leetcode - 445. 两数相加 II
OC and OD gate circuit
Classic application of MOS transistor circuit design (1) -iic bidirectional level shift
Talk about the circuit use of TVs tube
Several problems to be considered and solved in the design of multi tenant architecture
[NAS1](2021CVPR)AttentiveNAS: Improving Neural Architecture Search via Attentive Sampling (未完)
Esp8266 interrupt configuration
STM32 outputs 1PPS with adjustable phase
猜谜语啦(7)
Naming rules for FreeRTOS
QEMU demo makefile analysis
Example 007: copy data from one list to another list.
Summary of SIM card circuit knowledge
Imx6ull bare metal development learning 2- use C language to light LED indicator
2022.7.4-----leetcode.1200
Keil use details -- magic wand
实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.
FIO测试硬盘性能参数和实例详细总结(附源码)