题意:给定一个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. 转 Android HTTPS详解

    目录(?)[-] 前言 HTTPS原理 SSLTLS协议作用 基本的运行过程 握手阶段的详细过程 客户端发出请求ClientHello 服务器回应ServerHello 客户端回应 服务器的最后回应 ...

  2. char*赋值在常量区,不可以修改

    char*赋值在常量区,不可以修改,要想修改,用数组. char* = "abc";*(pCh+1) = 'k';//编译正常,运行报错. char pCh[] = "a ...

  3. DWR 整合之Struts2.3.16

    DWR 能够和任何框架结合. DWR 和 Struts 整合有 2 个层次.最基础的层次就是同时使用这两个框架,这是非常容易的,但是这样就不允许在 DWR 和 Struts 之间共享 Action 了 ...

  4. php7连不上mysql求帮忙!!!

    把php.ini中的 拓展mysqli.dll和pdo_mysql.dll前面分号都去掉也没用,mysql是5.5 apache2.4和php7都好使了,怎么也连不上mysql Fatal error ...

  5. Android4.2以后,多屏幕的支持 学习(一)

    前几天总结了Android的多用户支持,过几天准备再总结Android的多屏支持.Android支持3种类型屏幕:主屏幕(Primary Display).外屏幕(External Display)和 ...

  6. do from a specific ip

    ping -S 192.168.240.1 sohu.com telnet -b 192.168.240.1 sohu.com 80

  7. Subsequences Summing to Sevens

    Subsequences Summing to Sevens 题目描述 Farmer John's N cows are standing in a row, as they have a tende ...

  8. Unity3d之剥离alpha通道

    unity中, 将图集的 alpha 通道剥离出来可减少包体大小和内存使用大小. 方法是将原来的一张 rgba 图分成一张 rgb 和一张 alpha 图,android上rgb和alpha图均采用e ...

  9. BigDecimal 高精度计算 熟悉扩展,java除法保留小数问题

    java保留两位小数问题: 方式一: 四舍五入  double   f   =   111231.5585;  BigDecimal   b   =   new   BigDecimal(f);  d ...

  10. python之路: 基础篇

    )或>>> name = )    #按照占位符的顺序):]        #下标识从0开始的 wulaoer >>> print name[:]        # ...