Painting Storages

题目链接

  • 题意:

    给n个球,每个球可以涂成红色和蓝色任意一种,求相连的红色球的个数不少于m的涂色方案有多少种,结果对MOD取模

  • 分析:

    两种方法解决,第一种直接求,也可以求,就是状态转移略麻烦;另一种求对立问题,即相连的红色球的个数小于于m的涂色方案有多少种,这个相比第一个简单些,但是第一种也可以解决。采用第二种:

    dp[i]表示i位置放蓝球,满足题意的共几种方案。这个题目如果采用当前状态更新之后状态就比较麻烦,相等于每次区间更新;如果采用由之前的状态求出当前的未知状态就比较简单,区间和,用前缀和求

const int MAXN = 1100000;
int n, m, dp[MAXN], psm[MAXN], f[MAXN];
int main()
{
    f[0] = 1;
    FF(i, 1, MAXN)
        f[i] = f[i - 1] * 2 % MOD;
    while (~RII(n, m))
    {
        dp[0] = psm[0] = 1;
        FE(i, 1, n + 1)
        {
            dp[i] = psm[i - 1];
            if (i - m - 1 >= 0)
                dp[i] = ((dp[i] - psm[i - m - 1]) % MOD + MOD) % MOD;
            psm[i] = (psm[i - 1] + dp[i]) % MOD;
        }
        cout << ((f[n] - dp[n + 1]) % MOD + MOD) % MOD << endl;
    }
    return 0;
}
时间: 2024-10-12 15:15:07

Painting Storages的相关文章

[ACM] ZOJ 3725 Painting Storages (DP计数+组合)

Painting Storages Time Limit: 2 Seconds      Memory Limit: 65536 KB There is a straight highway with N storages alongside it labeled by 1,2,3,...,N. Bob asks you to paint all storages with two colors: red and blue. Each storage will be painted with e

ZOJ - 3725 Painting Storages

Description There is a straight highway with N storages alongside it labeled by 1,2,3,...,N. Bob asks you to paint all storages with two colors: red and blue. Each storage will be painted with exactly one color. Bob has a requirement: there are at le

(DP) zoj 3725

Painting Storages Time Limit: 2 Seconds      Memory Limit: 65536 KB There is a straight highway with N storages alongside it labeled by 1,2,3,...,N. Bob asks you to paint all storages with two colors: red and blue. Each storage will be painted with e

HDU - 4810 Wall Painting(组合数学)

Description Ms.Fang loves painting very much. She paints GFW(Great Funny Wall) every day. Every day before painting, she produces a wonderful color of pigments by mixing water and some bags of pigments. On the K-th day, she will select K specific bag

Cube painting UVA 253

说说:一看到给立方体染色,开始还有点小害怕.毕竟高中数学里染色问题从来都不会简单.这道题的意思就是给立方体的六个面染色,然后判断两个染了色的立方体是否一样.其实仔细一想,立方体无非三对面,若开始确定两对面.如下面图Figure 1所示:假设1,2,6,5这四个面先确定(这只有唯一一种情况)之后,再放3,4,的时候无非两种情况.但这两种情况是不一样的,这也许就是题目所说的reflection.开始的想法是找出三对面,然后比较是否相等即可,不过实在想不出怎样来排除reflection的情况.所以只能

Codeforces Round #256 (Div. 2) C. Painting Fence(分治贪心)

题目链接:http://codeforces.com/problemset/problem/448/C ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943

Line Painting

Line Painting Time limit: 2.0 secondMemory limit: 64 MB The segment of numerical axis from 0 to 109 is painted into white color. After that some parts of this segment are painted into black, then some into white again and so on. In total there have b

HNU13383:The Big Painting

Problem description Samuel W. E. R. Craft is an artist with a growing reputation. Unfortunately, the paintings he sells do not provide him enough money for his daily expenses plus the new supplies he needs. He had a brilliant idea yesterday when he r

Codeforces Gym 100342C Problem C. Painting Cottages 转化题意

Problem C. Painting CottagesTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description The new cottage settlement is organized near the capital of Flatland. The construction company that is building the settl