题目链接  Count Arrays

题意  给定$n$和$m$个区间。若一个长度为$n$的$01$序列满足对于每一个给定的区间中至少有一个位置是$0$,

那么这个$01$序列满足条件。求有多少满足条件的$01$序列。

设$f[i]$为考虑到第$i$位的时候,有多少满足条件的$01$序列。

则转移方程为$f[i] = ∑f[j]  (j < i)$,意义为当$f[j]$转移给了$f[i]$时,相当于贡献了$[j+1,i-1]$这段区间都为$1$的方案数。

于是按照题目给定的区间预处理出每个数的转移范围。

显然当$i$递增的时候,在转移范围之内的$j$的最小值是不下降的。

那么就可以通过这个单调性做到$O(n)$了。

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i) const int N = 1e5 + 10;
const int mod = 1e9 + 7; int n, m;
int c[N], f[N];
int now, cnt; int main(){ scanf("%d%d", &n, &m); rep(i, 1, m){
int x, y;
scanf("%d%d", &x, &y);
c[y + 1] = max(c[y + 1], x);
} f[now = 0] = cnt = 1; rep(i, 1, n + 1){
while (now < c[i]) cnt = (cnt - f[now++] + mod) % mod;
f[i] = cnt;
(cnt += f[i]) %= mod;
} printf("%d\n", f[n + 1]);
return 0;
}

CS Academy Round #65 Count Arrays (DP)的更多相关文章

  1. CS Academy Gcd on a Circle(dp + 线段树)

    题意 给你一个长为 \(n\) 的环,你可以把它断成任意 \(k\) 段 \((1 < k \le n)\) ,使得每一段的 \(\gcd\) 都 \(>1\) . 问总共有多少种方案,对 ...

  2. Codeforces Beta Round #13 C. Sequence (DP)

    题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...

  3. Educational Codeforces Round 51 D. Bicolorings(dp)

    https://codeforces.com/contest/1051/problem/D 题意 一个2*n的矩阵,你可以用黑白格子去填充他,求联通块数目等于k的方案数,答案%998244353. 思 ...

  4. codeforces 1288C. Two Arrays(dp)

    链接:https://codeforces.com/contest/1288/problem/C C. Two Arrays 题意:给定一个数n和一个数m,让构建两个数组a和b满足条件,1.数组中所有 ...

  5. CF1288C-Two Arrays (DP)

    You are given two integers n and m. Calculate the number of pairs of arrays (a,b) such that: the len ...

  6. Codeforces Round #300 Quasi Binary(DP)

    Quasi Binary time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  7. 背水一战 Windows 10 (65) - 控件(WebView): 对 WebView 中的内容截图, 通过 Share Contract 分享 WebView 中的被选中的内容

    [源码下载] 背水一战 Windows 10 (65) - 控件(WebView): 对 WebView 中的内容截图, 通过 Share Contract 分享 WebView 中的被选中的内容 作 ...

  8. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  9. Leetcode 943. Find the Shortest Superstring(DP)

    题目来源:https://leetcode.com/problems/find-the-shortest-superstring/description/ 标记难度:Hard 提交次数:3/4 代码效 ...

随机推荐

  1. Contest - 中南大学第六届大学生程序设计竞赛(Semilive)

    题1:1160十进制-十六进制 注意他给的数据范围 2^31,int是 2^31-1 #include<iostream> using namespace std; int main() ...

  2. 4 Template层-CSRF

    1.csrf 全称Cross Site Request Forgery,跨站请求伪造 某些恶意网站上包含链接.表单按钮或者JavaScript,它们会利用登录过的用户在浏览器中的认证信息试图在你的网站 ...

  3. 数据预处理之独热编码(One-Hot Encoding)

    问题的由来 在很多机器学习任务中,特征并不总是连续值,而有可能是分类值. 例如,考虑以下三个特征: ["male","female"] ["from ...

  4. package.json文件特殊符号含义

    package.json文件里的^和~表示什么意思呢 In the simplest terms, the tilde matches the most recent minor version (t ...

  5. 部署 Windows PowerShell Web 访问

    部署 Windows PowerShell Web 访问 适用对象:Windows Server 2012, Windows Server 2012 R2 Windows PowerShell® We ...

  6. couchbase map reduce

    map function(){emit(null,2);} reduce function(key, values, rereduce){ var response = {"a": ...

  7. winform DataGridView添加合计行

    使用方法 /* DataTable dt= DBUtility.DB.FromSql(sql).ToDataTable(); DataGridViewAddSumRow sumRow = new Da ...

  8. Spring整合hibernate -SessionFactory

    本文目录 1  本文采用 hibernate4 整合 Spring3.1 2 把Spring获取datasource通过class="org.springframework.orm.hibe ...

  9. Javascript 表达式和运算符

    属性访问表达式: var o = {x:1, y:{z:3}};//示例对象 var a = [o, 4, [5,6]];//包含对象的数组 console.log(o["x"]) ...

  10. js日期处理

    Js获取当前日期时间及其它操作 var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFullYear(); //获取完整 ...