2018. The Debut Album

http://acm.timus.ru/problem.aspx?space=1&num=2018

真心爱过,怎么能彻底忘掉

题目大意:

长度为n的串,由1和2组成,连续的1不能超过a个,连续的2不能超过b个

dpa[i] 表示长度为i时以a为结尾的串的个数,dpb[i] 类似

求dpa[i]时 需要枚举结尾a的个数就可以了 dpb[i] 类似

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <string.h>

using namespace std;

const int N=50001;
const int M=301;
const unsigned int MOD=1000000007;
unsigned int dpa[N];
unsigned int dpb[N];
int main()
{
    //freopen("data.in","r",stdin);
    memset(dpa,0,sizeof(dpa));
    memset(dpb,0,sizeof(dpb));
    int n,a,b;
    cin>>n>>a>>b;
    dpa[0]=dpb[0]=1;
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=a&&j<=i;++j)
        {
            dpa[i]=(dpa[i]+dpb[i-j])%MOD;
        }
        for(int j=1;j<=b&&j<=i;++j)
        {
            dpb[i]=(dpb[i]+dpa[i-j])%MOD;
        }
    }
    cout<<((dpa[n]+dpb[n])%MOD)<<endl;
    return 0;
}

  

时间: 2024-12-12 19:05:07

2018. The Debut Album的相关文章

ural 2018 The Debut Album

2018. The Debut Album Time limit: 2.0 secondMemory limit: 64 MB Pop-group “Pink elephant” entered on recording their debut album. In fact they have only two songs: “My love” and “I miss you”, but each of them has a large number of remixes. The produc

ural 2018. The Debut Album 滚动数组dp

点击打开链接 2018. The Debut Album Time limit: 2.0 second Memory limit: 64 MB Pop-group "Pink elephant" entered on recording their debut album. In fact they have only two songs: "My love" and "I miss you", but each of them has a la

URAL 2018 The Debut Album (DP)

题意:给出n长度的数列,其实1的连续个数不超过a,2的连续个数不超过b. 析:dp[i][j][k] 表示前 i 个数,以 j 结尾,并且连续了k个长度,要用滚动数组,要不然MLE. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath

Ural 2018The Debut Album(DP)

题目地址:Ural 2018 简单DP.用滚动数组. 代码例如以下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #include <map> #i

【动态规划】Gym - 100507G - The Debut Album

一般思路的dp是用f(i,j,0)表示前i位最后有j个1的方案数,用f(i,j,1)表示前j位最后有j个2的方案数,j都是大于等于1的,然后比较容易转移. 但这题卡内存,就只能用f(i,j)表示前i位最后有j个1的方案数,这里j大于等于0. 然后转移就略麻烦,自己看代码领会一下吧. 也可以看成是滚动数组优化. #include<cstdio> using namespace std; #define MOD 1000000007 int n,lim[2]; int f[50010][310],

sqlplus常用操作命令2

常用编辑命令:A[ppend] text 将text附加到当前行之后C[hange] /old /new 将当前行中的old替换为newCLear] buff[er] 清除缓冲区中的所有行DEL 删除当前行DEL x 删除第x行L[ist] 列出缓冲区中所有行L[ist] x 列出缓冲区中第x行R[un]或/ 运行缓冲区中保存的语句x 将第x行作为当前行 SQL> select product_id,name 2 from 3 products; PRODUCT_ID NAME --------

【转】C# 解析JSON方法总结

http://blog.csdn.net/jjhua/article/details/51438317 主要参考http://blog.csdn.NET/joyhen/article/details/24805899和http://www.cnblogs.com/yanweidie/p/4605212.html 根据自己需求,做些测试.修改.整理. 使用Newtonsoft.Json 一.用JsonConvert序列化和反序列化. 实体类不用特殊处理,正常定义属性即可,控制属性是否被序列化参照高

关于Oracle SQL/82标准和SQL/92标准

在ORACLE9i之前,oracle语法基础是SQL/86标准,9i及之后的版本中支持SQL/92标准.基表信息:products.purchases和product_types SQL> select * from products; PRODUCT_ID PRODUCT_TYPE_ID NAME DESCRIPTION PRICE ---------- --------------- ------------------------------ -----------------------

Python 提取Twitter用户的Tweet

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-31 @author: guaguastd @name: harvest_user_tweet.py ''' if __name__ == '__main__': # import json import json # import search from search import search_for_tweet # import harvest_use