Gym 100507G The Debut Album
来源:互联网 发布:服装erp软件排名 编辑:程序博客网 时间:2024/05/16 07:15
题目 http://codeforces.com/gym/100507
题意:
在n个位置填充1 or 2. 要求连续的1的个数不超过a,连续的2的个数不超过b. 求方案数.
跟以前做过的一道dp题差不多,都是套路
dp[i+j][0] 表示第i个位置填1,在i位置后面连续填j个2的方案个数
dp[i+j][1] 表示第i个位置填2,在i位置后面连续填j个1的方案个数
dp[i+j][0] += dp[i][1]
dp[i+j][1] += dp[i][0]
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <queue>#include <vector>#include <cmath>#include <stack>#include <string>#include <sstream>#include <map>#include <set>#define pi acos(-1.0)#define LL long long#define ULL unsigned long long#define inf 0x3f3f3f3f#define INF 1e18#define lson l,mid,rt<<1#define rson mid+1,r,rt<<1|1#define debug(a) printf("---%d---\n", a)#define mem0(a) memset(a, 0, sizeof(a))#define memi(a) memset(a, inf, sizeof(a))#define mem1(a) memset(a, -1, sizeof(a))using namespace std;typedef pair<int, int> P;const double eps = 1e-10;const int maxn = 1e6 + 5;const int mod = 1e9 + 7;LL dp[maxn][2];int main(void){//freopen("C:\\Users\\wave\\Desktop\\NULL.exe\\NULL\\in.txt","r", stdin); int n, a, b; while (cin >> n >> a >> b) { memset(dp, 0, sizeof(dp)); dp[0][0] = dp[0][1] = 1; for (int i = 0; i <= n; i++){ for (int j = 1; j <= a && i+j <= n; j++) dp[i + j][0] = (dp[i + j][0] + dp[i][1]) % mod; for (int j = 1; j <= b && i+j <= n; j++) dp[i + j][1] = (dp[i + j][1] + dp[i][0]) % mod; } cout << (dp[n][0] + dp[n][1]) % mod << endl; }return 0;}
0 0
- Gym 100507G The Debut Album
- Gym - 100507G G. The Debut Album 数位dp+内存优化
- codeforces (G) The Debut Album dp+滚动数组
- URAL - 2018 The Debut Album
- Ural 2018 The Debut Album
- Ural 2018. The Debut Album
- Ural 2018 The Debut Album
- SDKD 2017 Spring Team Training B G题 -The Debut Album or URAL
- Ural 2018The Debut Album(DP)
- URAL 2018 The Debut Album(dp)
- URAL2018——The Debut Album(DP)
- URAL 2018. The Debut Album (dp)
- The Debut Album (dp + 滚动数组)
- URAL 2018 The Debut Album(DP)
- 【DP】URAL 2018 The Debut Album
- ural 2018. The Debut Album 滚动数组dp
- URAL 2018 The Debut Album DP中滚动数组用法
- ☆URAL 2018 The Debut Album (dp 两种写法)
- jdbc关联模型查询-多表查询返回结果集
- hibernate快速新建数据表 方便测试
- LayoutInflater的inflate函数用法详解
- android中AsyncTask的使用
- mac
- Gym 100507G The Debut Album
- 设计模式之-代理模式
- CentOS 7.2 Mitaka云平台控制节点部署脚本(VLAN+VXLAN+DVR私有网络)
- Effective Java学习笔记: 第57条只针对异常的情况才使用异常
- LeetCode #187: Repeated DNA Sequences
- JAVA最常用的排序_冒泡排序、选择排序、快速排序
- Hadoop压缩方式
- Gridview的简单应用
- substring的一个易错点