URAL 2018 The Debut Album (DP)
题意:给出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)的更多相关文章
- ural 2018 The Debut Album(dp¥)
2018. The Debut Album Time limit: 2.0 secondMemory limit: 64 MB Pop-group “Pink elephant” entered on ...
- 2018. The Debut Album
http://acm.timus.ru/problem.aspx?space=1&num=2018 真心爱过,怎么能彻底忘掉 题目大意: 长度为n的串,由1和2组成,连续的1不能超过a个,连续 ...
- Ural 2018The Debut Album(DP)
题目地址:Ural 2018 简单DP.用滚动数组. 代码例如以下: #include <iostream> #include <cstdio> #include <st ...
- Gym 100507G The Debut Album (滚动数组dp)
The Debut Album 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/G Description Pop-group & ...
- URAL 1658. Sum of Digits(DP)
题目链接 隔了一年零三个月,重新刷URAL,这题挺麻烦的输出路径.输出路径挺扯的,乱写了写乱改改就A了...我本来想用很靠谱,记录每一条路径的,然后输出最小的,结果Tle,然后我使劲水水又过了一组,发 ...
- URAL 1776 C - Anniversary Firework DP
C - Anniversary FireworkTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/c ...
- Ural 1073 Square Country (DP)
题目地址:Ural 1073 DP水题.也能够说是背包. #include <iostream> #include <cstdio> #include <string&g ...
- 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 ...
- 【BZOJ1814】Ural 1519 Formula 1 插头DP
[BZOJ1814]Ural 1519 Formula 1 题意:一个 m * n 的棋盘,有的格子存在障碍,求经过所有非障碍格子的哈密顿回路个数.(n,m<=12) 题解:插头DP板子题,刷板 ...
随机推荐
- 推荐ajaxfilemanager for tiny_mce 比较完善的tiny_mce编辑器的图片上传及图片管理插件PHP版 支持中文
tiny_mce编辑器,我觉得挺简洁.好用的,但就是图片上传的插件是收费的,而且网上找了半天也没有找到开源好用的上传插件. 不过功夫不负有心人,终于还就被我找到一款相当满意的插件. 这个插件的名字叫a ...
- Kafka- Kafka架构功能
Kafka是一个高吞吐量的分布式消息系统,一个分布式的发布-订阅消息系统.Kafka是一种快速,可拓展的,设计内在就是分布式的,分区的可复制的提交日志服务. Apache Kafka与传统消息系统相比 ...
- jquery侧边折叠导航栏制作,两行代码搞定
jquery侧边折叠导航栏制作,两行代码搞定 //CSS*{margin: 0;padding: 0} ul{list-style: none} .menu li ul{display: none} ...
- unity3D中一些有用的设置
edit-project setting-time:可以设置fixed update()每一帧执行的时间 timescale:时间流动速度,设置为0则运用了time.deltatime的动画计时器均停 ...
- 计算地球上两个坐标点(经度,纬度)之间距离sql函数
go --计算地球上两个坐标点(经度,纬度)之间距离sql函数 --作者:lordbaby --整理:www.aspbc.com CREATE FUNCTION [dbo].[fnGetDistanc ...
- Python—numpy.bincount()
1.它大致说bin的数量比x中的最大值大1,每个bin给出了它的索引值在x中出现的次数.下面,我举个例子让大家更好的理解一下: # 我们可以看到x中最大的数为7,因此bin的数量为8,那么它的索引值为 ...
- iis_rewrite3突然无法使用(因为它过期啦)
转自http://www.b1y.cn/post/216.html ISAPI_Rewrite3完全版会有45天的试用期,过期了需要99美元进行够买,网上有很多破解版的,方法如下: 1.先从官网下一个 ...
- ajax stream 一边下载二进制数据一边处理
最近有在做 stream 下载,并且边下载 stream 边处理功能.解析二进制的功能.最初参考了 flv.js 的 flv stream 下载处理功能,发现他并没有使用的 XMLHttpReques ...
- flex 和bison的安装和使用
1.在ubutu上安装 yacc的命令: sudo apt-get install flex bison flex:词法分析器 flex是一个词法分析器.用来将一个.l文件生成一个.c程序文件.即生成 ...
- HihoCoder1338 A Game(记忆化搜索)
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi and Little Ho are playing a game. There is an integ ...