Codeforces 757D - Felicity's Big Secret Revealed
757D - Felicity's Big Secret Revealed
题目大意:给你一串有n(n<=75)个0或1组成的串,让你划最多n+1条分割线,第一条分割线的前面和最后一条分割线的后面
不算一段。设剩下的段里面的最大值为max,若1-max都在这些段里面出现过则算一个有效划分,问你总共有多少有效划分,
答案对1e9+7取模。
写的时候感觉是个dp,单就是想不出来,看了题解说是状态压缩dp,把出现过哪些数字当做状态,这样才写出来的QAQ。
思路:因为n<=75,我们列一下,最大值肯定不会超过20,这样我们就能状态压缩了。
dp[ i ][ j ]表示,最后一条划分线在第 i 个数后面,状态为 j 的划分数。这样我们就可以枚举划分的第一个数,
再枚举这个段的长度k,如果这个段对应的十进制的值为w,那么状态转移方程为 dp[ i + k -1 ] [ j | ( 1 << ( w - 1 ) ) ]+=dp[ i - 1 ][ j ];
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=;
const int M=;
const ll mod=1e9+;
int dp[N][(<<M)+];//dp[i][j] 表示最后一个划分线在i后面状态为j的划分数。
int a[N],n,pow2[];
int work(int l,int r,int len)
{
int c=len-,ans=;
for(int i=l;i<=r;i++)
{
ans+=a[i]*pow2[c];
c--;
}
return ans;
}
int main()
{
int up=<<M;
pow2[]=;
for(int i=;i<=;i++) pow2[i]=pow2[i-]*;
cin>>n;
for(int i=;i<=n;i++) scanf("%1d",&a[i]);
for(int i=;i<=n;i++) dp[i][]=;
for(int i=;i<=n;i++)
{
for(int j=;j<up;j++)
{
if(!dp[i-][j]) continue;
for(int k=;k<=n-;k++)//枚举长度最大不是5位 如00000001,这个wa了几次
{
if(i+k>n) break;
int w=work(i,i+k,k+);
if(w>) break;//这里不判断会RE
if(w>=) dp[i+k][j|(<<(w-))]=(dp[i+k][j|(<<(w-))]+dp[i-][j])%mod;
}
}
}
int ans=;
for(int i=;i<=n;i++)
{
int now=;
int p=;
for(int j=;j<=;j++)
{
p+=now;
ans=(ans+dp[i][p])%mod;
now*=;
}
}
cout<<ans<<endl;
return ;
}
Codeforces 757D - Felicity's Big Secret Revealed的更多相关文章
- CodeForces 757D Felicity's Big Secret Revealed(状压DP)
题意:给定一个01串,一个有效的n切割定义如下:一个横杠代表一次切割,第一条横杠前面的01串不算,最后一条横杠后面的01串不算,将两个横杠中的01串转化成十进制数字,假设这些数字的最大值是MAX且这些 ...
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined)D. Felicity's Big Secret Revealed
题目连接:http://codeforces.com/contest/757/problem/D D. Felicity's Big Secret Revealed time limit per te ...
- Codeforces 757 D. Felicity's Big Secret Revealed 状压DP
D. Felicity's Big Secret Revealed The gym leaders were fascinated by the evolutions which took pla ...
- 【codeforces 757D】Felicity's Big Secret Revealed
[题目链接]:http://codeforces.com/problemset/problem/757/D [题意] 给你一个01串; 让你分割这个01串; 要求2切..n+1切; 对于每一种切法 所 ...
- Codeforces 757C. Felicity is Coming!
C. Felicity is Coming! time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- 【CodeForces】925 C.Big Secret 异或
[题目]C.Big Secret [题意]给定数组b,求重排列b数组使其前缀异或和数组a单调递增.\(n \leq 10^5,1 \leq b_i \leq 2^{60}\). [算法]异或 为了拆位 ...
- [Codeforces Round #194 (Div. 2)] Secret 解题报告 (数学)
题目链接:http://codeforces.com/problemset/problem/334/C 题目: 题目大意: 给定数字n,要求构建一个数列使得数列的每一个元素的值都是3的次方,数列之和S ...
- Codeforces Round #391 A B C D E
A. Gotta Catch Em' All! 题意 从给定的字符串中选取字符,问可构成多少个\(Bulbasaur\) // 想到柯南里一些从报纸上剪汉字拼成的恐吓信_(:з」∠)_ Code #i ...
- ethereum/EIPs-1077 Executable Signed Messages
https://github.com/alexvandesande/EIPs/blob/ee2347027e94b93708939f2e448447d030ca2d76/EIPS/eip-1077.m ...
随机推荐
- C# Dictionary序列化/反序列化
[Serializable] public class SerializableDictionary<TKey, TValue> : Dictionary<TKey, TValue& ...
- This page is about building Firefox Desktop
This page is about building Firefox Desktop The Mozilla build system, like the rest of the Mozilla c ...
- js委托事件和代理事件
转载出处:https://www.cnblogs.com/liugang-vip/p/5616484.html js中的事件委托或是事件代理详解 起因: 1.这是前端面试的经典题型,要去找工作的小伙伴 ...
- Maven打包编译找不到com.sun.crypto.provider.SunJCE类
Maven配置 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>mav ...
- 公共模块定义/草案(Common Module Definition / draft - CMD草案)
This specification addresses how modules should be written in order to be interoperable in browser-b ...
- Linux下的换行符\n\r以及txt和word文档的使用
Linux doc WINDOWS下记事本编写的文档和LINUX下VIM或者GEDIT等编写的文档的不同! 例如WINDOWS下编写的SH脚本,放到LINUX下执行可能会出错. 解决方法: 原因是:W ...
- 【Shell】带颜色输出(白底x色)
echo -e "\033[31mHello World.\033[0m" 红色31m 绿色32m 黄色33m 蓝色34m 黑色30m 白色37m 紫色35m 深绿色36m
- DDR3基本知识及测试【转】
转自:http://blog.csdn.net/myarrow/article/details/7847385 一.DDR3简介 DDR3(double-data-rate three synchro ...
- eclipse自动生成变量名声明(按方法返回值为本地变量赋值)
eclipse自动生成变量名声明(按方法返回值为本地变量赋值) ctrl+2+L 这个快捷键可自动补全代码,极大提升编码效率! 注:ctrl和2同时按完以后释放,再快速按L.不能同时按! 比如写这句代 ...
- Mac 安装多个python环境
1.安装Homebrew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/ ...