一般思路的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],g[50010];
int main()
{
//freopen("g.in","r",stdin);
scanf("%d%d%d",&n,&lim[0],&lim[1]);
f[1][0]=f[1][1]=1;
g[1]=1;
for(int i=2;i<=n;++i)
{
for(int k=1;k<=lim[0] && k<=i;++k)
{
f[i][k]=(f[i][k]+f[i-1][k-1])%MOD;
g[i]=(g[i]+f[i][k])%MOD;
}
for(int k=1;k<=lim[1] && k<=i-1;++k)
f[i][0]=(f[i][0]+g[i-k])%MOD;
if(i<=lim[1])
f[i][0]=(f[i][0]+1)%MOD;
}
int ans=0;
for(int k=0;k<=lim[0] && k<=n;++k)
ans=(ans+f[n][k])%MOD;
printf("%d\n",ans);
return 0;
}

【动态规划】Gym - 100507G - The Debut Album的更多相关文章

  1. Gym 100507G The Debut Album (滚动数组dp)

    The Debut Album 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/G Description Pop-group & ...

  2. ural 2018 The Debut Album(dp¥)

    2018. The Debut Album Time limit: 2.0 secondMemory limit: 64 MB Pop-group “Pink elephant” entered on ...

  3. 2014-2015 ACM-ICPC, NEERC, Eastern Subregional Contest Problem G. The Debut Album

    题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229669 时间限制:1s 空间限制:64MB 题目大意:给定n,a,b的值 求一个长度为n的 ...

  4. 2018. The Debut Album

    http://acm.timus.ru/problem.aspx?space=1&num=2018 真心爱过,怎么能彻底忘掉 题目大意: 长度为n的串,由1和2组成,连续的1不能超过a个,连续 ...

  5. URAL 2018 The Debut Album (DP)

    题意:给出n长度的数列,其实1的连续个数不超过a,2的连续个数不超过b. 析:dp[i][j][k] 表示前 i 个数,以 j 结尾,并且连续了k个长度,要用滚动数组,要不然MLE. 代码如下: #p ...

  6. Ural 2018The Debut Album(DP)

    题目地址:Ural 2018 简单DP.用滚动数组. 代码例如以下: #include <iostream> #include <cstdio> #include <st ...

  7. Json.net 常用使用小结

    using System; using System.Linq; using System.Collections.Generic; namespace microstore { public int ...

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

    http://blog.csdn.net/jjhua/article/details/51438317 主要参考http://blog.csdn.NET/joyhen/article/details/ ...

  9. NEERC 2014, Eastern subregional contest

    最近做的一场比赛,把自己负责过的题目记一下好了. Problem B URAL 2013 Neither shaken nor stirred 题意:一个有向图,每个结点一个非负值,可以转移到其他结点 ...

随机推荐

  1. 怎么将数据库从Oracle迁移到SQL Server,或从Oracle迁移到MySQL

    有时候我们有迁移数据库的需求,例如从Oracle迁移到SQL Server,或者从MySQL迁移到Oracle. 很多江湖好汉一时不知如何手工操作,所幸的是Navicat提供了迁移的自动化操作界面. ...

  2. nodejs 喜欢报cannot find module .....的简单解决方案

    在安装nodejs后使用命令npm install <package_name>一直喜欢报cannot find module........ 因为我之前在我的电脑上安装过nodejs,当 ...

  3. IDEA2017 使用(二)

    1.鼠标悬浮在方法上显示api 2.关闭拼写检查 3.自动导入包(存在多个包时需要手动导入) 4.设置方法线

  4. fuser命令找到占用资源的进程

    fuser 概述 fuser命令是用来显示所有正在使用着指定的file, file system 或者 sockets的进程信息. 例一: #fuser –m –u /mnt/usb1 /mnt/us ...

  5. 在线输入RGB更改背景色

    HTML: <!DOCTYPE html><html> <head> <meta http-equiv="Content-Type" co ...

  6. 布局之BFC

    BFC 什么是BFC,在哪里需要用到BFC,BFC有什么规则?生成BFC有什么条件?这几个问题,我将为大家一一解释,下面我们进入正题. BFC(Block formatting context)直译为 ...

  7. vue2.0基础知识,及webpack中vue的使用

    ## 基础指令 ## [v-cloak]{         Display:none;     }     <p v-cloak>xx{{msg}}xx</p> //解决闪烁问 ...

  8. 【Foreign】阅读 [线段树][DP]

    阅读 Time Limit: 10 Sec  Memory Limit: 256 MB Description Input Output Sample Input 0 10 4 10 2 3 10 8 ...

  9. python 调用Linux shell

    有时候难免需要直接调用Shell命令来完成一些比较简单的操作,比如mount一个文件系统之类的.那么我们使用Python如何调用Linux的Shell命令?下面来介绍几种常用的方法: 1. os 模块 ...

  10. IOS工程自动打包并发布脚本实现

    http://blog.csdn.net/ccf0703/article/details/8588667 文章首发地址:http://webfrogs.me/2013/02/18/ios-automa ...