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;
}
2018. The Debut Album的更多相关文章
- ural 2018 The Debut Album(dp¥)
2018. The Debut Album Time limit: 2.0 secondMemory limit: 64 MB Pop-group “Pink elephant” entered on ...
- URAL 2018 The Debut Album (DP)
题意:给出n长度的数列,其实1的连续个数不超过a,2的连续个数不超过b. 析:dp[i][j][k] 表示前 i 个数,以 j 结尾,并且连续了k个长度,要用滚动数组,要不然MLE. 代码如下: #p ...
- Gym 100507G The Debut Album (滚动数组dp)
The Debut Album 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/G Description Pop-group & ...
- Ural 2018The Debut Album(DP)
题目地址:Ural 2018 简单DP.用滚动数组. 代码例如以下: #include <iostream> #include <cstdio> #include <st ...
- 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的 ...
- 【动态规划】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位 ...
- NEERC 2014, Eastern subregional contest
最近做的一场比赛,把自己负责过的题目记一下好了. Problem B URAL 2013 Neither shaken nor stirred 题意:一个有向图,每个结点一个非负值,可以转移到其他结点 ...
- 递推,求至少连续放置三个U的危险组合
UVA580-Critical Mass 题意 有两种方块,L和U,有至少三个连续的U称为危险组合,问有多少个危险组合 solution: 至少这个概念比较难求 ,所以转化为(1ll<<n ...
- Json.net 常用使用小结
using System; using System.Linq; using System.Collections.Generic; namespace microstore { public int ...
随机推荐
- Qt设计师学习笔记--Sharping-Changing Dialogs
1.pushbutton->default属性为true,按回车相当于点击该按钮. 2.选中checkable后,Button变成切换按钮(toggle button),可以有两种状态:按下/弹 ...
- JavaACOFramework的各个类介绍(part1 : Ant类)
public abstract class Ant extends Observable implements Runnable { public static int ANT_ID = 1; // ...
- 蚁群算法简介(part 1:蚁群算法之绪论)
群算法是Marco Dorigo在1992年提出的一种优化算法,该算法受到蚂蚁搜索食物时对路径的选择策略的启示.蚁群算法作为群体智能算法的一种利用分布式的种群搜索策略来寻找目标函数的最优解.蚁群算法与 ...
- python基础 Day01 练习题
1 字符串格式化 #!/urs/bin/env python name = input("Name: ") age = int(input("Age: ")) ...
- 手势(UIGestureRecognizer)
通过继承 UIGestureRecognizer 类,实现自定义手势(手势识别器类). PS:自定义手势时,需要 #import <UIKit/UIGestureRecognizerSubcla ...
- 在C#中读取枚举值的描述属性
枚举: public enum EnumLanugage { [System.ComponentModel.Description("中文")] Chinese, English ...
- 在Ubuntu下使用 csapp.h 和 csapp.c
它山之石可以攻玉. 对于<深入理解计算机系统>这本神人写就的神书, 我等凡人就不评论什么啦. 这本书的 第二,三 部分, 真的真的对我理解操作系统有很大的帮助. (当然, 如果你不看第一部 ...
- Top命令 -转
Windows下的任务管理器虽然不好用(个人更喜欢Process Explorer些),但也算方便,可以方便的查看进程,CPU,内存...也可以很容易的结束进程 没有图形化界面下的Linux,也有命令 ...
- 网易云音乐PC端刷曲快捷键
文章首发于szhshp的第三边境研究所(szhshp.org), 转载请注明 网易云音乐PC端刷曲快捷键 好吧我承认我特别懒 云音乐其实做的还不错,FM推荐的算法明显比虾米好. 虾米可以听的曲子都 ...
- 学习PYTHON之路, DAY 6 - PYTHON 基础 6 (模块)
一 安装,导入模块 安装: pip3 install 模块名称 导入: import module from module.xx.xx import xx from module.xx.xx impo ...