Codeforces Round #631 (Div. 2) Dreamoon Likes Sequences

题面很短,别的博客也讲了就不说题意了。

做法:

异或是没有进位的加法,所以ai + 1的二进制最高位要大于ai的二进制最高位,才能满足ai递增,bi也递增的条件。呐这样的话,选了4,(5,6,7)就都不能选了,只能选比7大的数。

这样分析下来a数组最长也只有30,(2^30>1e9)

直接按照数字大小dp会TLE

思路角度1:换一个角度,我们把二进制最高位相同的看作一组,因为这一组内只能选一个数。

有点像分组背包。但是我们现在只看分组背包的方案数,所以就不用枚举每一组内的物品了。

dpij表示考虑到前i组,选了其中j组的方案数。

cnt[i]表示第i组有多少个

dpij += dpi-1j-1*cnt[i] 考虑要第i组

dpij += dpi-1j 考虑不要第i组

然后就可以了

我写的时候顺便空间优化了下

https://paste.ubuntu.com/p/YjzM6RmPWC/

思路角度2:换一个角度,我们把二进制最高位相同的看作一组

dpi 表示以第i组为结尾的序列的方案数。

cnt[i]表示第i组有多少个

dpi  += dpk * cnt[i] (k 从0枚举到i - 1)

https://paste.ubuntu.com/p/vxPHns2YVJ/

原文地址:https://www.cnblogs.com/AlexPanda/p/12631435.html

时间: 2024-08-03 10:57:02

Codeforces Round #631 (Div. 2) Dreamoon Likes Sequences的相关文章

数学 Codeforces Round #219 (Div. 2) B. Making Sequences is Fun

题目传送门 1 /* 2 数学:这题一直WA在13组上,看了数据才知道是计算cost时超long long了 3 另外不足一个区间的直接计算个数就可以了 4 */ 5 #include <cstdio> 6 #include <cmath> 7 #include <iostream> 8 #include <algorithm> 9 #include <cstring> 10 using namespace std; 11 12 typedef

Codeforces Round #631 (Div. 2) D.Dreamoon Likes Sequences

题目连接:Dreamoon Likes Sequences  题意:给你d和m,让你构造一个递增数组a,使数组b(i==1,b[i]=a[i] ; i>1, b[i]=b[i-1]^a[i])递增,求a有几种,答案模m. 题解:根据异或的性质可以得出:2后边不能有3, 4后边不能有5~7, 8后边不能有9~15...... 然后就很好写了.用数组b记录第i个数可以取得数有多少个,数组dp记录长度为 i 的 a 数组有几种.看下边的代码应该就清楚了. 1 #include<bits/stdc++

Codeforces Round #631 (Div. 2) C. Dreamoon Likes Coloring(贪心好题/意识流题解)

Dreamoon likes coloring cells very much. There is a row of nn cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 11 to nn . You are given an integer mm and mm integers l1,l2,…,lml1,l2,…,lm (1≤li≤n1≤li≤n ) Dreamoo

Codeforces Round #631 (Div. 2) B. Dreamoon Likes Permutations(排列组合)

The sequence of mm integers is called the permutation if it contains all integers from 11 to mm exactly once. The number mm is called the length of the permutation. Dreamoon has two permutations p1p1 and p2p2 of non-zero lengths l1l1 and l2l2 . Now D

Codeforces Round #272 (Div. 2) Dreamoon and WiFi 暴力

B. Dreamoon and WiFi Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them. Each command is one of the following two types: Go 1 unit towards the

Codeforces Round #162 (Div. 1) B. Good Sequences (dp+分解素数)

题目:http://codeforces.com/problemset/problem/264/B 题意:给你一个递增序列,然后找出满足两点要求的最长子序列 第一点是a[i]>a[i-1] 第二点 gcd(a[i],a[i-1])>1 也就是说两个数不能互质 找出最长的子序列长度 思路:首先想互质问题,如果两个数互质说明两个数之间没有素因子相同,我们想以每个素因子结尾的最大长度是多少 然后比如样例 2 3 4 6 9 第一个数 2      2结尾 1 第二个数 3      3结尾 1 第三

Codeforces Round #631 (Div. 2)

A 用桶维护即可 #include <bits/stdc++.h> using namespace std; const int N = 205; int t,n,x,a[N],b[N]; signed main() { ios::sync_with_stdio(false); cin>>t; while(t--) { cin>>n>>x; for(int i=1;i<=n;i++) cin>>a[i]; memset(b,0,sizeof

Codeforces Round #631 (Div. 2) - Thanks, Denis aramis Shitov!

A题 题意: 给n个数据,m次操作,使得1~A,全都出现.如果其中有数据没在n里出现,就m-- 思路: 模拟就行 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 #define ull unsigned long long 5 #define il inline 6 #define it register int 7 #define inf 0x3f3f3f3f 8 #define lowbit

Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi (超几何分布)

题目链接:Codeforces Round #273 (Div. 2) B. Dreamoon and WiFi 题意:"+"表示前进1个单位,"-"表示后退1个单位,问以0为起点经过S1,S2两个命令后达到的位置相同的概率. 思路:统计"+"和"-"的数量.如果S2中的"+"或者"-"比S1中的多,概率是0.其他条件下,形成的是超几何分布. AC代码: #include <std