当前位置:网站首页>暑假第一周
暑假第一周
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;
}
边栏推荐
- Working principle and type selection of common mode inductor
- leetcode - 445. 两数相加 II
- Synchronization of QT multithreading
- 關於線性穩壓器的五個設計細節
- Explain task scheduling based on Cortex-M3 in detail (Part 2)
- Google sitemap files for rails Projects - Google sitemap files for rails projects
- Is the security account given by Yixue school safe? Where can I open an account
- Sword finger offer 06 Print linked list from end to end
- Esphone retrofits old fans
- Matlab tips (28) fuzzy comprehensive evaluation
猜你喜欢
DCDC circuit - function of bootstrap capacitor
Xrosstools tool installation for X-Series
QEMU STM32 vscode debugging environment configuration
Sword finger offer 06 Print linked list from end to end
Agile project management of project management
STM32 virtualization environment of QEMU
Various types of questions judged by prime numbers within 100 (C language)
实例004:这天第几天 输入某年某月某日,判断这一天是这一年的第几天?
319. 灯泡开关
猜谜语啦(7)
随机推荐
List of linked lists
NTC thermistor application - temperature measurement
UE像素流,来颗“减肥药”吧!
STM32 outputs 1PPS with adjustable phase
Go dependency injection -- Google open source library wire
【三层架构】
Working principle and type selection of common mode inductor
猜谜语啦(10)
Classic application of MOS transistor circuit design (2) - switch circuit design
STM32 --- configuration of external interrupt
Cmder of win artifact
STM32 lights up the 1.8-inch screen under Arduino IDE
Example 006: Fibonacci series
实例010:给人看的时间
Void* C is a carrier for realizing polymorphism
Five design details of linear regulator
【NOI模拟赛】汁树(树形DP)
Count the number of inputs (C language)
实例001:数字组合 有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?
[paper reading] the latest transfer ability in deep learning: a survey in 2022