题目连接:http://codeforces.com/contest/757/problem/D

D. Felicity's Big Secret Revealed
time limit per test

4 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

The gym leaders were fascinated by the evolutions which took place at Felicity camp. So, they were curious to know about the secret behind evolving Pokemon.

The organizers of the camp gave the gym leaders a PokeBlock, a sequence of n ingredients. Each ingredient can be of type 0 or 1. Now the organizers told the gym leaders that to evolve a Pokemon of type k (k ≥ 2), they need to make a valid set of k cuts on the PokeBlock to get smaller blocks.

Suppose the given PokeBlock sequence is b0b1b2... bn - 1. You have a choice of making cuts at n + 1 places, i.e., Before b0, between b0and b1, between b1 and b2, ..., between bn - 2 and bn - 1, and after bn - 1.

The n + 1 choices of making cuts are as follows (where a | denotes a possible cut):

b0 | b1 | b2 | ... | bn - 2 | bn - 1 |

Consider a sequence of k cuts. Now each pair of consecutive cuts will contain a binary string between them, formed from the ingredient types. The ingredients before the first cut and after the last cut are wasted, which is to say they are not considered. So there will be exactly k - 1 such binary substrings. Every substring can be read as a binary number. Let m be the maximum number out of the obtained numbers. If all the obtained numbers are positive and the set of the obtained numbers contains all integers from 1 to m, then this set of cuts is said to be a valid set of cuts.

For example, suppose the given PokeBlock sequence is 101101001110 and we made 5 cuts in the following way:

10 | 11 | 010 | 01 | 1 | 10

So the 4 binary substrings obtained are: 11, 010, 01 and 1, which correspond to the numbers 3, 2, 1 and 1 respectively. Here m = 3, as it is the maximum value among the obtained numbers. And all the obtained numbers are positive and we have obtained all integers from 1 to m. Hence this set of cuts is a valid set of 5 cuts.

A Pokemon of type k will evolve only if the PokeBlock is cut using a valid set of k cuts. There can be many valid sets of the same size. Two valid sets of k cuts are considered different if there is a cut in one set which is not there in the other set.

Let f(k) denote the number of valid sets of k cuts. Find the value of . Since the value of s can be very large, output smodulo 109 + 7.

Input

The input consists of two lines. The first line consists an integer n (1 ≤ n ≤ 75) — the length of the PokeBlock. The next line contains the PokeBlock, a binary string of length n.

Output

Output a single integer, containing the answer to the problem, i.e., the value of s modulo 109 + 7.

Examples
input
4
1011
output
10
input
2
10
output
1
Note

In the first sample, the sets of valid cuts are:

Size 2: |1|011, 1|01|1, 10|1|1, 101|1|.

Size 3: |1|01|1, |10|1|1, 10|1|1|, 1|01|1|.

Size 4: |10|1|1|, |1|01|1|.

Hence, f(2) = 4, f(3) = 4 and f(4) = 2. So, the value of s = 10.

In the second sample, the set of valid cuts is:

Size 2: |1|0.

Hence, f(2) = 1 and f(3) = 0. So, the value of s = 1.

题意:给你一个长度为N的01字符串(N<=75),对字符串进行划分,要使得划分的每一部分转换为十进制数出现了一到m(m为转换的最大值)、

题解:dp[i][j]表示在第i个字符结尾j状态的方案数(j表示的状态是j转换成二进制第k位为1的话表示前面的i划分出现过k这个值)

转移方程为dp[k][j|1<<(x-1)]=∑dp[i][j](x为i到k的字符串转换为十进制的那个数)由于字符串最大长度为75则x的最大值为20;然后对答案就是

dp[i][j](0《i《n,j=((1<<k)-1)(1<=k<=20))的和

#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int N=; const int mod=1e9+;
int n,a[N];
char b[N];
int dp[N][(<<)+];
int main()
{
scanf("%d",&n);
scanf("%s",b+);
for(int i=;i<=n;i++)
{
a[i]=b[i]-'';
}
for(int i=;i<=n;i++)
{
dp[i][]=;
for(int j=;j<(<<);j++)
{
if(dp[i][j])
{
ll x=;
for(int k=i+;k<=n;k++)
{
x+=a[k];
if(x>)break;
if(!x)continue;
dp[k][j|<<(x-)]=(dp[k][j|<<(x-)]+dp[i][j])%mod;
x*=;
}
}
}
}
int ans=;
for(int i=;i<=n;i++)
{
for(int j=;j<=;j++)
{
ans=(ans+dp[i][(<<j)-])%mod;
}
}
printf("%d\n",ans);
}

Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined)D. Felicity's Big Secret Revealed的更多相关文章

  1. Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题

    Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题 [Problem Description] ​ 总共两次询 ...

  2. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  3. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  4. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  5. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  6. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  7. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  8. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  9. Educational Codeforces Round 39 (Rated for Div. 2) G

    Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...

随机推荐

  1. [js高手之路]node js系列课程-图解express+supervisor+ejs用法

    上文通过node js自带的http模块搭建了一个简易的服务器,实际在开发中,一般用的是express框架,本文我们就来讲讲项目开发中必备不可少的几样东西: 服务器( express ) 路由( ex ...

  2. JSON 理解

    转自: http://blog.csdn.net/qyf_5445/article/details/8635578 (json很全面的理解) http://www.cnblogs.com/haitao ...

  3. vue中引入swiper(vue中的滑块组件vue-awesome-swiper)

    第一步安装 npm install vue-awesome-swiper --save 第二部在main.js中引入 import VueAwesomeSwiper from 'vue-awesome ...

  4. java 多线程Callable和Runable执行顺序问题详解

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt125 毫无疑问 Runnable会进行异步执行,此处不多说,主要说明Call ...

  5. protobuf和thrift对比

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt383 数据类型 protobuf thrift protobuf thrif ...

  6. django源码解析一(请求处理流程)

    1.我们都知道WSGI是一个规范,规范了server和application之间通信的一些约束,server端在监听到请求之后,会把请求转给application去处理,他们之间关联起来的桥梁是一个e ...

  7. IPsec_VPN实现技术【转载】

    GRE Tunnel GRE Tunnel(General Routing Encapsulation 通用路由封装)是一种非常简单的VPN(Virtual Private Network 虚拟专用网 ...

  8. 【深入Java虚拟机】之一:Java内存区域与内存溢出

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/17565503 内存区域 Java虚拟机在执行Java程序的过程中会把他所管理的内存划分为若 ...

  9. MongoDB学习之路(四)

    MongoDB插入文档 MongoDB使用insert()或save()方法向集合中插入文档. db.COLLECTION_NAME.insert(document); For instance &g ...

  10. Java语言课程设计——博客作业教学数据分析系统(201521123107 张翔)

    #Java语言课程设计--博客作业教学数据分析系统(个人博客) 1.团队课程设计博客链接 [博客作业教学数据分析系统(From:网络五条狗)](http://www.cnblogs.com/fanta ...