Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined)D. Felicity's Big Secret Revealed
题目连接:http://codeforces.com/contest/757/problem/D
4 seconds
512 megabytes
standard input
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.
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 a single integer, containing the answer to the problem, i.e., the value of s modulo 109 + 7.
4
1011
10
2
10
1
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的更多相关文章
- Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题
Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题 [Problem Description] 总共两次询 ...
- 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 ...
- 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 ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- 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 ...
- 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 ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- 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 < ...
随机推荐
- AVAssetWriter 硬编码bug解决
一.需求 直播助手在录屏过程中,产品要求跟随用户手机屏幕旋转,录屏的视频跟随旋转 二.实施方案 目前触手录,iTools PC端均已经实现该功能,并且该功能只适配iOS9和iOS10系统.猜测实现方案 ...
- VS2013禁用Browser Link
禁用原因 VS2013新增的Browser Link功能虽然“强大”,但我并不需要. 但默认是开启的,会在页面中自动添加如下的代码,查看AJAX时造成很大的干扰. <!-- Visual Stu ...
- 如何搭建Zookeeper集群
ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件.它是一个为分布式应用提供一致性服务的软件,提供的 ...
- JVM启动参数设置
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt174 不管是YGC还是Full GC,GC过程中都会对导致程序运行中中断,正 ...
- android-学习1 配置环境
转载注明出处,谢谢--http://www.cnblogs.com/JK-HYJ/ 前提:电脑先配置好java的环境-- adk_bundle下载安装地址:http://tools.android-s ...
- angular之scope.$watch
某“大神”挖了个陨石坑,我于是乎似懂非懂的接手,玩了一个月angular.现在项目告一段落,暂别了繁重的重复性工作,可以开始回顾.认真的折腾下之前犹抱琵琶的angular. angular吸引人的特性 ...
- wait与sellp方法区别
Java Thread(线程)案例详解sleep和wait的区别 上次对Java Thread有了总体的概述与总结,当然大多都是理论上的,这次我将详解Thread中两个常用且容易疑惑的方法.并通 ...
- tomcat学习笔记
1.安装和运行[必须] * 解压apache-tomcat-6.0.35.zip * 位置:不能包含中文和空格 * 运行: %tomcat%/bin/startup.bat * 测试 * http:/ ...
- 201521123060 《Java程序设计》第7周学习总结
1. 本周学习总结 2. 书面作业 1.ArrayList代码分析 1.1 解释ArrayList的contains源代码 答:contains方法调用indexOf方法,遍历遍历内部用于保存数据的e ...
- 201521123109《java程序设计》第二周学习总结
1. 本周学习总结 (1)学习了字符串String的类型,使用Arrays对数组的处理及其相关的应用 (2)学会使用码云 (3)了解了对象与封装 (4)学会查询Java API文件 2. 书面作业 ( ...