题意:给定一个01串,一个有效的n切割定义如下:一个横杠代表一次切割,第一条横杠前面的01串不算,最后一条横杠后面的01串不算,将两个横杠中的01串转化成十进制数字,假设这些数字的最大值是MAX且这些数字囊括了1-MAX的所有数字,则称为一次有效切割。求2~n+1次有效切割的切法。

思路: 由于题目要求包含所有1—MAXN的数字,且n<=75,所以MAXN<=20。另dp[i][j]表示第i位前面有一个横杆且存在j这个状态,接着从第i位开始枚举到第j位为下一个横杆的位置,设这两段横杆之间的数字为p(十进制),则递推式子为

dp[j+1][k|(1<<p-1)]+=dp[i][k],k为1~(1<<20)的状态。最后把dp[i][(1<<t)-1](0<=i<=n,1<=t<=20)加起来就可以了。

 #include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <sstream>
#include <time.h>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define lson l,m,rt*2
#define rson m+1,r,rt*2+1
#define mt(A,B) memset(A,B,sizeof(A))
#define mod 1000000007
using namespace std;
typedef long long LL;
const double PI = acos(-);
const int N=1e5+;
const int inf = 0x3f3f3f3f;
const LL INF=0x3f3f3f3f3f3f3f3fLL;
int dp[][(<<)+];
int a[];
int main()
{
#ifdef Local
freopen("data","r",stdin);
#endif
int n,p,ans=;
cin>>n;
mt(dp,);
for(int i=;i<n;i++)scanf("%1d",&a[i]);
for(int i=;i<n;i++)
{
dp[i][]=;
for(int k=;k<(<<);k++)
{
if(!dp[i][k])continue;
for(int j=i,p=a[i];j<n&&p<=;j++,p=((p<<)+a[j]))
{
if(p)dp[j+][k|(<<p-)]=(dp[j+][k|(<<p-)]+dp[i][k])%mod;
}
}
}
for(int i=;i<=n;i++)
{
for(int k=;k<=;k++)
{
ans=(ans+dp[i][(<<k)-])%mod;
}
}
cout<<ans<<endl;
#ifdef Local
cerr << "time: " << (LL) clock() * / CLOCKS_PER_SEC << " ms" << endl;
#endif
}

CodeForces 757D Felicity's Big Secret Revealed(状压DP)的更多相关文章

  1. 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 ...

  2. Codeforces 757D - Felicity's Big Secret Revealed

    757D - Felicity's Big Secret Revealed 题目大意:给你一串有n(n<=75)个0或1组成的串,让你划最多n+1条分割线,第一条分割线的前面和最后一条分割线的后 ...

  3. Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP

    Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10061 ...

  4. Educational Codeforces Round 13 E. Another Sith Tournament 状压dp

    E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rul ...

  5. Codeforces 1225G - To Make 1(bitset+状压 dp+找性质)

    Codeforces 题目传送门 & 洛谷题目传送门 还是做题做太少了啊--碰到这种题一点感觉都没有-- 首先我们来证明一件事情,那就是存在一种合并方式 \(\Leftrightarrow\) ...

  6. CF1103D Codeforces Round #534 (Div. 1) Professional layer 状压 DP

    题目传送门 https://codeforces.com/contest/1103/problem/D 题解 失去信仰的低水平选手的看题解的心路历程. 一开始看题目以为是选出一些数,每个数可以除掉一个 ...

  7. Codeforces 279D The Minimum Number of Variables 状压dp

    The Minimum Number of Variables 我们定义dp[ i ][ mask ]表示是否存在 处理完前 i 个a, b中存者 a存在的状态是mask 的情况. 然后用sosdp处 ...

  8. codeforces#580 D. Kefa and Dishes(状压dp)

    题意:有n个菜,每个菜有个兴奋值,并且如果吃饭第i个菜立即吃第j个菜,那么兴奋值加ma[i][j],求吃m个菜的最大兴奋值,(n<=18) 分析:定义dp[status][last],statu ...

  9. Codeforces Round #585 (Div. 2) E. Marbles(状压dp)

    题意:给你一个长度为n的序列 问你需要多少次两两交换 可以让相同的数字在一个区间段 思路:我们可以预处理一个数组cnt[i][j]表示把i放到j前面需要交换多少次 然后二进制枚举后 每次选择一个为1的 ...

随机推荐

  1. HTTPS与SSL

    ---------------------------------------------------------------------------------------------------- ...

  2. easyui tree使用方法

    加载数据 $('#treeul').tree({ checkbox:true, url:'initTree.aspx', onLoadSuccess:function(){ //绑定权限 $.ajax ...

  3. FusionCharts使用问题及解决方法(二)-FusionCharts常见问题大全

    在上文中,我们介绍了FusionCharts常见问题(FAQ)的解决方法,本文将一同讨论FusionCharts使用者面临的一些复杂问题的解决方法. 如何启用JavaScript调试模式? 要启用Ja ...

  4. 介绍Angular的注入服务

    其实angular的注入服务是挺复杂的,目前看源码也只看懂了一半,为了不误导大家,我也不讲敢讲太复杂,怕自己都理解错了. 首先我们要知道angular的三种注入方式: 第一种:inference va ...

  5. Java回调函数的理解

    所谓回调,就是客户程序C调用服务程序S中的某个函数A,然后S又在某个时候反过来调用C中的某个函数B,对于C来说,这个B便叫做回调函数.例如Win32下的窗口过程函数就是一个典型的回调函数.一般说来,C ...

  6. NDK常用命令

    NDK Build 用法(NDK Build)   1.ndk-build的用法 Android NDKr4引入了一个新的.小巧的shell脚本ndk-build,来简化源码编译. 该文件位于NDK根 ...

  7. [转]makefile文件的编写规则及实例

    http://xueqi.iteye.com/blog/1567866   1.一个简单的makefile例子   假设一个程序有两个文件file1.c,file2.c,每个文件都包含head.h,生 ...

  8. HDU 5523 Game

    坑题 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> us ...

  9. fragment 数据传递,传值,通信

    [原][Fragment精深系列4]Fragment与Activity之间的数据交互 2015-5-26阅读389 评论0   以下内容来自于自己的实践和网络资料的整理,希望对你有帮助. 一.Acti ...

  10. Kubernetes 1.4 部署

    k8s 1.4 新版本部署 测试环境: node-: 10.6.0.140 node-: 10.6.0.187 node-: 10.6.0.188 kubernetes 集群,包含 master 节点 ...