• Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined)D. Felicity's Big Secret Revealed


    题目连接: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=80; 
     
    const int mod=1e9+7; 
    int n,a[N];
    char b[N]; 
    int dp[N][(1<<20)+10]; 
    int main()
    {
        scanf("%d",&n);
        scanf("%s",b+1);
        for(int i=1;i<=n;i++)
        {
            a[i]=b[i]-'0'; 
        }
        for(int i=0;i<=n;i++)
        {
            dp[i][0]=1;
            for(int j=0;j<(1<<20);j++)
            {
                if(dp[i][j])
                {
                    ll x=0;
                    for(int k=i+1;k<=n;k++)
                    {
                        x+=a[k];
                        if(x>20)break;
                        if(!x)continue;
                        dp[k][j|1<<(x-1)]=(dp[k][j|1<<(x-1)]+dp[i][j])%mod;    
                        x*=2; 
                    } 
                } 
            } 
        } 
        int ans=0; 
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=20;j++)
            {
                ans=(ans+dp[i][(1<<j)-1])%mod; 
            } 
        }
        printf("%d
    ",ans); 
    } 
  • 相关阅读:
    华硕ASUS A3V 拆解图 http://m.linktone.com/report/pdjj/14001781862.shtml
    华硕A3V 迅驰 配置详情
    Dvbbs 更换论坛置顶图片
    Flash 图片轮换效果
    动网官方最新dvbbs7.1sp1商业版下载,附存储过程解密代码!
    在VC中为应用程序添加图形超链接功能
    VC常见数据类型转换详解
    查询Access逻辑字段遇到的问题 武胜
    几个不错的开源的.net界面控件 转自http://zchuang2004.spaces.live.com/blog/cns!8C4AEEE059DED8B1!157.entry 武胜
    C#正则表达式整理备忘 转载(http://www.cnblogs.com/KissKnife/archive/2008/03/23/1118423.html) 武胜
  • 原文地址:https://www.cnblogs.com/lhclqslove/p/7423165.html
Copyright © 2020-2023  润新知