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& ...
- jsp/servlet页面跳转丢失样式问题
问题:使用servlet,如何处理在多路径页面跳转中servlet转发页面样式丢失问题?(例如访问 http://localhost/project/listUser.action后转到http:// ...
- Jsp (Java Server Pages)相关知识九大内置对象和四大作用域
一.初识JSP Jsp页面的组成:静态内容.指令.表达式.小脚本.声明.标准动作.注释等元素构成 Url:统一资源定位符 Url组成:协议.主机名(包括端口号).路径 1.注释的方式: 1.HTML注 ...
- luogu 1972 小H的项链 莫队
1.莫队算法 TLE 80 #include<bits/stdc++.h> #define rep(i,x,y) for(register int i=x;i<=y;i++) usi ...
- 公共模块定义/草案(Common Module Definition / draft - CMD草案)
This specification addresses how modules should be written in order to be interoperable in browser-b ...
- adboost方法(转载)
转载链接:http://blog.csdn.net/google19890102/article/details/46376603 一.集成方法(Ensemble Method) 集成方法主要 ...
- 字符驱动之二操作方法(struct file_operations)【转】
转自:http://blog.chinaunix.net/uid-26837113-id-3157515.html 从上一篇我们看到了字符驱动的三个重要结构,那我现在跟大家详细的说说 struct f ...
- ftruncate(改变文件大小)
ftruncate(改变文件大小) 定义函数 int ftruncate(int fd,off_t length); 函数说明 ftruncate()会将参数fd指定的文件大小改为参数length指定 ...
- GetStockObject 理解
原文地址:https://www.cnblogs.com/Clingingboy/archive/2013/04/13/3017952.html GetStockObject在图形编程中是常用API之 ...
- vuejs初学入门环境搭建
一.Nodejs: 1.安装下载:http://nodejs.cn/download/ 2.Node.js安装配置: http://www.runoob.com/nodejs/nodejs ...