当前位置:网站首页>暑假第一周
暑假第一周
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;
}边栏推荐
猜你喜欢

Sword finger offer 05 Replace spaces

实例004:这天第几天 输入某年某月某日,判断这一天是这一年的第几天?

Briefly talk about the identification protocol of mobile port -bc1.2

Typical low code apaas manufacturer cases
![[noi simulation] juice tree (tree DP)](/img/19/bc71e8dc3958e4cb87b31423a74617.png)
[noi simulation] juice tree (tree DP)

DokuWiki deployment notes

UE像素流,来颗“减肥药”吧!

More than 90% of hardware engineers will encounter problems when MOS tubes are burned out!

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

实例010:给人看的时间
随机推荐
Arduino operation stm32
Sword finger offer 05 Replace spaces
287. 寻找重复数-快慢指针
每日一题——输入一个日期,输出它是该年的第几天
關於線性穩壓器的五個設計細節
剑指 Offer 05. 替换空格
Several implementation schemes of anti reverse connection protection of positive and negative poles of power supply!
UE pixel stream, come to a "diet pill"!
Detailed summary of FIO test hard disk performance parameters and examples (with source code)
QEMU demo makefile analysis
How can fresh students write resumes to attract HR and interviewers
Use indent to format code
Explain task scheduling based on Cortex-M3 in detail (Part 1)
More than 90% of hardware engineers will encounter problems when MOS tubes are burned out!
MySQL之MHA高可用集群
Apaas platform of TOP10 abroad
Example 009: pause output for one second
Sizeof (function name) =?
2020-05-21
Matlab tips (28) fuzzy comprehensive evaluation