【动态规划】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],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的更多相关文章
- Gym 100507G The Debut Album (滚动数组dp)
The Debut Album 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/G Description Pop-group & ...
- ural 2018 The Debut Album(dp¥)
2018. The Debut Album Time limit: 2.0 secondMemory limit: 64 MB Pop-group “Pink elephant” entered on ...
- 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的 ...
- 2018. The Debut Album
http://acm.timus.ru/problem.aspx?space=1&num=2018 真心爱过,怎么能彻底忘掉 题目大意: 长度为n的串,由1和2组成,连续的1不能超过a个,连续 ...
- URAL 2018 The Debut Album (DP)
题意:给出n长度的数列,其实1的连续个数不超过a,2的连续个数不超过b. 析:dp[i][j][k] 表示前 i 个数,以 j 结尾,并且连续了k个长度,要用滚动数组,要不然MLE. 代码如下: #p ...
- Ural 2018The Debut Album(DP)
题目地址:Ural 2018 简单DP.用滚动数组. 代码例如以下: #include <iostream> #include <cstdio> #include <st ...
- Json.net 常用使用小结
using System; using System.Linq; using System.Collections.Generic; namespace microstore { public int ...
- 【转】C# 解析JSON方法总结
http://blog.csdn.net/jjhua/article/details/51438317 主要参考http://blog.csdn.NET/joyhen/article/details/ ...
- NEERC 2014, Eastern subregional contest
最近做的一场比赛,把自己负责过的题目记一下好了. Problem B URAL 2013 Neither shaken nor stirred 题意:一个有向图,每个结点一个非负值,可以转移到其他结点 ...
随机推荐
- 固定width但是有间隔
<!DOCTYPE > <html> <head> <title></title> <meta name="name&quo ...
- bzoj4759 [Usaco2017 Jan]Balanced Photo
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4759 [题解] 排序,从大到小插入,树状数组统计. # include <vector ...
- 【Atcoder】ARC083 D - Restoring Road Network
[算法]图论,最短路? [题意]原图为无向连通图,现给定原图的最短路矩阵,求原图最小边权和,n<=300. [题解]要求最小边权和下,原图的所有边一定是所连两端点的最短路. 那么现在将所有最短路 ...
- [Leetcode Week9]Minimum Path Sum
Minimum Path Sum 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/minimum-path-sum/description/ Descr ...
- Linux kernel中断子系统之(五):驱动申请中断API【转】
转自:http://www.wowotech.net/linux_kenrel/request_threaded_irq.html 一.前言 本文主要的议题是作为一个普通的驱动工程师,在撰写自己负责的 ...
- JSP(2) - JSP指令 - 小易Java笔记
JSP指令是给JSP引擎用的,即给服务器用的.作用是告诉服务器,该如何处理JSP中除了指令之外的内容.包括page.include.taglib三种 基本的语法格式:<%@ 指令名称 属性1=& ...
- nodejs的包管理器npm和cnpm
http://www.ydcss.com/archives/18 3.npm介绍 3.1.说明:npm(node package manager)nodejs的包管理器,用于node插件管理(包括安装 ...
- fullpage.js jq全屏滚动插件
fullPage.js和fullPage都能实现全屏滚动,二者区别是:fullPage.js需依赖于JQuery库,而fullPage不需要依赖任何一个js库,可以单独使用. (代码演示效果并且可以下 ...
- selenium+python在mac环境上的搭建【转载】
前言 mac自带了python2.7的环境,所以在mac上安装selenium环境是非常简单的,输入2个指令就能安装好 需要安装的软件: 1.pip 2.selenium2.53.6 3.Firefo ...
- serialVersionUID的作用(zz)
http://www.cnblogs.com/guanghuiqq/archive/2012/07/18/2597036.html 简单来说,Java的序列化机制是通过在运行时判断类的serialVe ...