CodeForces 757D Felicity's Big Secret Revealed(状压DP)

题意:给定一个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)的更多相关文章
- 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
757D - Felicity's Big Secret Revealed 题目大意:给你一串有n(n<=75)个0或1组成的串,让你划最多n+1条分割线,第一条分割线的前面和最后一条分割线的后 ...
- 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 ...
- Educational Codeforces Round 13 E. Another Sith Tournament 状压dp
E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rul ...
- Codeforces 1225G - To Make 1(bitset+状压 dp+找性质)
Codeforces 题目传送门 & 洛谷题目传送门 还是做题做太少了啊--碰到这种题一点感觉都没有-- 首先我们来证明一件事情,那就是存在一种合并方式 \(\Leftrightarrow\) ...
- CF1103D Codeforces Round #534 (Div. 1) Professional layer 状压 DP
题目传送门 https://codeforces.com/contest/1103/problem/D 题解 失去信仰的低水平选手的看题解的心路历程. 一开始看题目以为是选出一些数,每个数可以除掉一个 ...
- Codeforces 279D The Minimum Number of Variables 状压dp
The Minimum Number of Variables 我们定义dp[ i ][ mask ]表示是否存在 处理完前 i 个a, b中存者 a存在的状态是mask 的情况. 然后用sosdp处 ...
- codeforces#580 D. Kefa and Dishes(状压dp)
题意:有n个菜,每个菜有个兴奋值,并且如果吃饭第i个菜立即吃第j个菜,那么兴奋值加ma[i][j],求吃m个菜的最大兴奋值,(n<=18) 分析:定义dp[status][last],statu ...
- Codeforces Round #585 (Div. 2) E. Marbles(状压dp)
题意:给你一个长度为n的序列 问你需要多少次两两交换 可以让相同的数字在一个区间段 思路:我们可以预处理一个数组cnt[i][j]表示把i放到j前面需要交换多少次 然后二进制枚举后 每次选择一个为1的 ...
随机推荐
- 转 Android HTTPS详解
目录(?)[-] 前言 HTTPS原理 SSLTLS协议作用 基本的运行过程 握手阶段的详细过程 客户端发出请求ClientHello 服务器回应ServerHello 客户端回应 服务器的最后回应 ...
- 把MSSQL的表数据查询成 insert into格式的函数
USE [db] GO /****** Object: StoredProcedure [dbo].[proc_insert] Script Date: 12/05/2012 17:18:31 *** ...
- CentOS 6.5添加163源
1.首先备份/etc/yum.repos.d/CentOS-Base.repo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS ...
- 关于UIView及其子类重绘drawRect
转载自:https://nezha.gitbooks.io/ios-developmentarticles/content/UIView%E7%9A%84drawRect%E9%87%8D%E7%BB ...
- mahout 查看kmeans结果的命令
$mahout seqdumper -i output/clusters-1/part-r-00000 直接在控制台上显示,要写入文件可以在后面加上-o <输出路径> mahout中的k ...
- PAT (Advanced Level) 1077. Kuchiguse (20)
最长公共后缀.暴力. #include<cstdio> #include<cstring> #include<cmath> #include<vector&g ...
- PAT (Advanced Level) 1043. Is It a Binary Search Tree (25)
简单题.构造出二叉搜索树,然后check一下. #include<stdio.h> #include<algorithm> using namespace std; +; st ...
- Android音频系统之音频框架
1.1 音频框架 转载请注明,From LXS, http://blog.csdn.net/uiop78uiop78/article/details/8796492 Android的音频系统在很长一段 ...
- mytop
http://jeremy.zawodny.com/mysql/mytop/mytop.html 内容有点过时,用?查看帮助 vi set nuset nonu总记不住
- 使用eclipse和maven一步一步配置web项目
http://www.blogjava.net/kevonz/archive/2012/07/08/382542.html