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板子题,刷板 ...
随机推荐
- java深入探究04
1.Http协议 tcp/ip关注的是客户端服务器之间数据是否传输成功 http协议:是在tcp/ip协议之间封装的一层协议关注的是传输格式是否规范 注意:系统自带的telent工具(远程访问工具)可 ...
- sqoop导入增量数据
使用sqoop导入增量数据. 核心参数 --check-column 用来指定一些列,这些列在增量导入时用来检查这些数据是否作为增量数据进行导入,和关系行数据库中的自增字段及时间戳类似这些被指定的列的 ...
- java备份和恢复数据代码例子
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.F ...
- Oracle学习笔记_03_单行函数
1.SQL函数: 单行函数.多行函数 单行函数: 操作数据对象 接受参数返回一个结果 只对一行进行变换 每行返回一个结果 可以转换数据类型 ...
- STL defalloc.h
defalloc.h . // Filename: defalloc.h . . // Comment By: 凝霜 . // E-mail: mdl2009@vip.qq.com . // Blog ...
- android sqlite,大数据处理、同时读写
1. 批量写入,采用事物方式,先缓存数据,再批量写入数据,极大提高了速度 288条,直接inset into 耗时7秒 8640条, 批量写入 耗时5-7秒 try { this.myD ...
- FFmpeg 基本用法
FFmpeg FFmpeg 基本用法 本课要解决的问题 1.FFmpeg的转码流程是什么? 2.常见的视频格式包含哪些内容吗? 3.如何把这些内容从视频文件中抽取出来? 4.如何从一种格式转换为另一种 ...
- xcopy语法
xcopy语法 2007-02-09 13:29:45| 分类: 服务器 | 标签:xcopy语法 |字号 订阅复制文件和目录,包括子目录. 语法 xcopySource [Destination] ...
- python 爬取腾讯视频评论
import urllib.request import re import urllib.error headers=('user-agent','Mozilla/5.0 (Windows NT 1 ...
- openfire存储中文字符乱码解决办法
转载于: Xmpp问题总结:处理Openfire 中文乱码问题(2) openfire是一个非常不错的IM服务器,而且是纯Java实现,具有多个平台的版本,他的数据存储可以采用多种数据库,如MySQL ...