一般思路的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。

然后转移就略麻烦,自己看代码领会一下吧。

也可以看成是滚动数组优化。

  1. #include<cstdio>
  2. using namespace std;
  3. #define MOD 1000000007
  4. int n,lim[2];
  5. int f[50010][310],g[50010];
  6. int main()
  7. {
  8. //freopen("g.in","r",stdin);
  9. scanf("%d%d%d",&n,&lim[0],&lim[1]);
  10. f[1][0]=f[1][1]=1;
  11. g[1]=1;
  12. for(int i=2;i<=n;++i)
  13. {
  14. for(int k=1;k<=lim[0] && k<=i;++k)
  15. {
  16. f[i][k]=(f[i][k]+f[i-1][k-1])%MOD;
  17. g[i]=(g[i]+f[i][k])%MOD;
  18. }
  19. for(int k=1;k<=lim[1] && k<=i-1;++k)
  20. f[i][0]=(f[i][0]+g[i-k])%MOD;
  21. if(i<=lim[1])
  22. f[i][0]=(f[i][0]+1)%MOD;
  23. }
  24. int ans=0;
  25. for(int k=0;k<=lim[0] && k<=n;++k)
  26. ans=(ans+f[n][k])%MOD;
  27. printf("%d\n",ans);
  28. return 0;
  29. }

【动态规划】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. 用spring的@Validated注解和org.hibernate.validator.constraints.*的一些注解在后台完成数据校验

    这个demo主要是让spring的@Validated注解和hibernate支持JSR数据校验的一些注解结合起来,完成数据校验.这个demo用的是springboot. 首先domain对象Foo的 ...

  2. [CVPR2018]Learning to Adapt Structured Output Space for Semantic Segmentation

    学习适应结构化输出空间进行语义分割 在语义分割场景中,虽然物体在外表上不同,但是他们的输出是结构化且共享很多例如空间分布, 局部内容等信息.所以作者提出了multi-level的输出空间adaptat ...

  3. 洛谷 PT2 First Step (ファーストステップ)

    题目背景 知らないことばかりなにもかもが(どうしたらいいの?) 一切的一切 尽是充满了未知数(该如何是好) それでも期待で足が軽いよ(ジャンプだ!) 但我仍因满怀期待而步伐轻盈(起跳吧!) 温度差なん ...

  4. 使用APICloud打包webapp

    做个记录: 参照apicloud官方文档:http://docs.apicloud.com/Dev-Tools/sublime-apicloud-plugin 可以看下我的github:https:/ ...

  5. Jasper语音助理

    1. 介绍 Jasper是一款基于树莓派的开源语音控制助理, 使用Python语言开发. Jasper工作原理主要是设备被动监听麦克风, 当收到唤醒关键字时进入主动监听模式, 此时收到语音指令后进行语 ...

  6. GitLab版本管理【转】

    转自:http://www.cnblogs.com/wintersun/p/3930900.html GitLab是利用 Ruby on Rails 一个开源的版本管理系统,实现一个自托管的Git项目 ...

  7. locust===Writing a locustfile

    The Locust class A locust class represents one user (or a swarming locust if you will). Locust will ...

  8. 关于preempt_enable 和 preempt_disable 【转】

    转自:http://blog.chinaunix.net/uid-8478094-id-2031177.html 关于preempt_enable 和 preempt_disable 允许抢占和禁止抢 ...

  9. 取Session数据语句在应放在哪里

    UsersModel loginUser = (UsersModel)Session["usersModel"]; 直接放在 public partial class PagesF ...

  10. 【bzoj2212&3702】二叉树

    线段树合并入门题. 分别计算左子树的逆序对,右子树的逆序对,合并的时候计算贡献. #include<bits/stdc++.h> #define N 8000005 using names ...