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 < ...
随机推荐
- python appium 操作app
下面是一些Python脚本中操作app的用法: 检查app安装情况(返回true/false), driver.is_app_installed(package_name) 安装app driver. ...
- NSA武器库知识整理
美国国家安全局(NSA)旗下的"方程式黑客组织"(shadow brokers)使用的部分网络武器被公开,其中包括可以远程攻破全球约70%Windows机器的漏洞利用工具. 其中, ...
- node.js 89行爬虫爬取智联招聘信息
写在前面的话, .......写个P,直接上效果图.附上源码地址 github/lonhon ok,正文开始,先列出用到的和require的东西: node.js,这个是必须的 request,然发 ...
- jQuery EasyUI弹出确认对话框(确认操作中.....)
因为毕业设计的原因,在初期设计系统的时候没有考虑功能的正确性,所以很多的功能都没有加验证和确认的操作,给人在操作方面上有一些不好的感觉(可能失误点击后,数据就别删除,或者增加了),所以在网上找了一些资 ...
- eval浅解
关于eval,你了解多少呢?来看看 eval() 函数可计算某个字符串,并执行其中的的 JavaScript 代码. 需要一个参数(string),切必需.要计算的字符串,其中含有要计算的 JavaS ...
- jdk源码研究1-HashMap
今天开始,研读下jdk的常用类的一些源码,下面是jdk中HashMap的研究.诚然,网上已经很多这方面的总结了,但是,个人只是想单纯地把自己的理解过程进行记录,大牛们就绕路吧,当然,欢迎扔砖头.下面是 ...
- js中面向对象的写法
function Circle(r){ this.r = r; }//构造(实例对象的)函数[思路二:这是一个类] Circle.PI = 3.14159; //属性 Circle.prototype ...
- C++ Primmer 学习笔记
一.开始 (一)输入输出 1.endl的作用 endl操纵符用于结束当前行,将与设备关联的缓冲区内容刷新到设备中.如果没有这个字符,一旦程序突然崩溃,就可能导致输出还停留在缓冲区里,而不显示到设备. ...
- mysql外键设置选项
. cascade方式 在父表上update/delete记录时,同步update/delete掉子表的匹配记录 . set null方式 在父表上update/delete记录时,将子表上匹配记录的 ...
- 201521123035《Java程序设计》第七周学习总结
1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 参考资料: XMind 2. 书面作业 1.ArrayList代码分析 1.1 解释ArrayList的contains源代 ...