题意:给出n长度的数列,其实1的连续个数不超过a,2的连续个数不超过b。

析:dp[i][j][k] 表示前 i 个数,以 j 结尾,并且连续了k个长度,要用滚动数组,要不然MLE。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e16;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
LL dp[2][2][310]; int main(){
int a, b;
cin >> n >> a >> b;
dp[0][0][1] = dp[0][1][1] = 1;
int cnt = 1;
LL sum1 = 1, sum2 = 1;
for(int i = 1; i < n; ++i, cnt ^= 1){
dp[cnt][0][1] = sum1;
dp[cnt][1][1] = sum2;
swap(sum1, sum2);
for(int j = 2; j <= a; ++j){
dp[cnt][0][j] = dp[cnt^1][0][j-1];
sum2 = (sum2 + dp[cnt][0][j]) % mod;
}
for(int j = 2; j <= b; ++j){
dp[cnt][1][j] = dp[cnt^1][1][j-1];
sum1 = (sum1 + dp[cnt][1][j]) % mod;
}
}
LL ans = (sum1 + sum2) % mod;
cout << ans << endl;
return 0;
}

  

URAL 2018 The Debut Album (DP)的更多相关文章

  1. ural 2018 The Debut Album(dp¥)

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

  2. 2018. The Debut Album

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

  3. Ural 2018The Debut Album(DP)

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

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

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

  5. URAL 1658. Sum of Digits(DP)

    题目链接 隔了一年零三个月,重新刷URAL,这题挺麻烦的输出路径.输出路径挺扯的,乱写了写乱改改就A了...我本来想用很靠谱,记录每一条路径的,然后输出最小的,结果Tle,然后我使劲水水又过了一组,发 ...

  6. URAL 1776 C - Anniversary Firework DP

    C - Anniversary FireworkTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/c ...

  7. Ural 1073 Square Country (DP)

    题目地址:Ural 1073 DP水题.也能够说是背包. #include <iostream> #include <cstdio> #include <string&g ...

  8. bzoj 1814 Ural 1519 Formula 1 插头DP

    1814: Ural 1519 Formula 1 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 942  Solved: 356[Submit][Sta ...

  9. 【BZOJ1814】Ural 1519 Formula 1 插头DP

    [BZOJ1814]Ural 1519 Formula 1 题意:一个 m * n 的棋盘,有的格子存在障碍,求经过所有非障碍格子的哈密顿回路个数.(n,m<=12) 题解:插头DP板子题,刷板 ...

随机推荐

  1. 某国际知名IT公司笔试

    原文地址:http://blog.csdn.net/lazy_tiger/article/details/1790986 这段时间没怎么顾及自己的这个“一寸土地”, 实在惭愧.因为这些天小弟又经历了“ ...

  2. Spring Cloud之Swagger2 API接口管理

    随着微服务架构体系的发展和应用, 为了前后端能够更好的集成与对接,同时为了项目的方便交付,每个项目都需要提供相应的API文档. 来源:PC端.微信端.H5端.移动端(安卓和IOS端) 传统的API文档 ...

  3. 剑指offer之 二叉搜索树的后续遍历序列

    题目描述: 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果.如果是则输出Yes,否则输出No.假设输入的数组的任意两个数字都互不相同. public class Solution { ...

  4. php 简单判断是否微信浏览器

    今天遇到一问题,让一个页面在微信上打开和浏览器打开显示不同的按钮,这是一个建议的方法 $user_agent = $_SERVER['HTTP_USER_AGENT']; if (strpos($us ...

  5. hdu-1286 找新朋友(欧拉函数,水题)

    题目链接: 找新朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  6. mysql删除重复数据方法

    create table tmp SELECT * from lhb t where t.id not in (select max(id) from lhb group by code,date,r ...

  7. sql根据坐标算距离

    CREATE FUNCTION ConvertXYToDistance(@la1 DECIMAL,@lo1 DECIMAL,@la2 DECIMAL,@lo2 DECIMAL)RETURNS FLOA ...

  8. 为啥要去IOE——分布式架构的由来

    1946年2.14日,那是一个浪漫的情人节 , 世界上第一台电子数字计算机在美国宾夕法尼亚大学诞生了,她的名字叫ENIAC.这台计算机占地170平米.重达 30 吨,每秒可以进行 5000 次加法运算 ...

  9. ECMAScript基本函数、概念区分总结

    1.使用Number()和parseInt() parseFloat()转换区别. 详见<JavaScript高级程序设计>P30 Number()可以针对任何类型. parseInt() ...

  10. HDOJ5441(图论中的并查集)

    #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ; ; ; ...