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 ...
随机推荐
- AfxBeginThread中使用updatedata出错
原因:MFC对象不支持多线程操作,不能供多个线程进程使用,所以尽量不要在线程里面更新界面. 解决办法: 1.将工程改为release 2.使用控件来SetWindowText 3.在线程里面发送消息 ...
- 【leetcode❤python】 125. Valid Palindrome
#-*- coding: UTF-8 -*- class Solution(object): def isPalindrome(self, s): ""&quo ...
- python之路3:
class set(object): """ set() -> new empty set object set(iterable) -> new set o ...
- underscore api
http://files.cnblogs.com/files/hwd13/underscore.rar
- stst
静态代码块如果不要static 那么只要生成新的该对象,则会执行{}内的代码 super.onDestroy() 先后顺序问题 Ctrl + Alt + F refromat code目前看来不能对代 ...
- Redis学习-基础环境介绍(二)
1.通过VMware安装了Centos6.8系统 2.Reids安装过程,需要GCC环境 »通过下面命令,根据提示直接安装 1 yum install gcc 3.Redis选用的是3.2.4(建议使 ...
- Asp.NET Visible属性与HTML display:none
作为Asp.NET 程序猿,我们经常会遇到客户端HTML 元素与 WebPage Server端控件互操作的情景.如果没有很好的掌握两种技术的细节就很容易发生一些“莫名其妙的错误”. 我最近犯的一个错 ...
- understanding ECMAscript 6 ---- block bindings
Traditionally, the way variable declarations work has been one tricky part of programming in javascr ...
- 求助sublime snippet
单个文件多个snippets不能生效?求助!(已解决) 文件保存路径:F:\work\sublime\Data\Packages\User\completions\xp.sublime-complet ...
- react+redux完整项目
地址:https://segmentfault.com/a/1190000007642740?utm_source=tuicool&utm_medium=referral