1202 子序列个数(DP)
第1行:一个数N,表示序列的长度(1 <= N <= 100000)
第2 - N + 1行:序列中的元素(1 <= a[i] <= 100000)
输出a的不同子序列的数量Mod 10^9 + 7。
4
1
2
3
2
13 //容易想到是 dp ,dp[i] 以 i 位置为结尾的子序列个数
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <sstream>
# include <set>
# include <cmath>
# include <algorithm>
# pragma comment(linker,"/STACK:102400000,102400000")
using namespace std;
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define LL long long
#define MX 100005 int n;
int dat[MX];
int zhi[MX];
int pre[MX];
LL sum[MX];
LL dp[MX]; int main()
{
scanf("%d",&n);
for (int i=;i<=n;i++)
{
scanf("%d",dat+i);
pre[i] = zhi[dat[i]];
zhi[dat[i]] = i;
}
for (int i=;i<=n;i++)
{
if (pre[i]==)
dp[i] = (sum[i-] + )%MOD;
else
dp[i] = (sum[i-] - sum[pre[i]-] + MOD)%MOD;
sum[i] = (sum[i-] + dp[i])%MOD;
}
printf("%lld\n",sum[n]);
return ;
}
1202 子序列个数(DP)的更多相关文章
- 51NOD 1202 子序列个数 DP
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1202&judgeId=225600 这题看起来挺复杂,但是真正的 ...
- 51nod 1202 子序列个数
1202 子序列个数 题目来源: 福州大学 OJ 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 收藏 关注 子序列的定义:对于一个序列a=a[1],a[2] ...
- 51nod 1202 不同子序列个数 [计数DP]
1202 子序列个数 题目来源: 福州大学 OJ 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 收藏 关注 子序列的定义:对于一个序列a=a[1],a[2],.. ...
- 51nod 1202 不同子序列个数(计数DP)
1202 子序列个数 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 子序列的定义:对于一个序列a=a[1],a[2],......a[n].则非空序列a'=a[p1],a ...
- 51nod1202 子序列个数
看到a[i]<=100000觉得应该从这个方面搞.如果a[x]没出现过,f[x]=f[x-1]*2;否则f[x]=f[x-1]*2-f[pos[a[x]]-1];ans=f[n]-1,然后WA了 ...
- FZU 2129 子序列个数 (递推dp)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2129 dp[i]表示前i个数的子序列个数 当a[i]在i以前出现过,dp[i] = dp[i - 1]*2 - ...
- hdu4632 Palindrome subsequence 回文子序列个数 区间dp
Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65535 K (Java/ ...
- fzuoj Problem 2129 子序列个数
http://acm.fzu.edu.cn/problem.php?pid=2129 Problem 2129 子序列个数 Accept: 162 Submit: 491Time Limit: ...
- 子序列个数(fzu2129)
子序列个数 Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
随机推荐
- Linux学习笔记 (七)挂载命令
在Linux中,光盘,U盘,硬盘在使用之前必须进行挂载,挂载类似windows中的分配盘符. 一.查看挂载和自动挂载 1.mount:直接输入mount表示查看系统中所有的挂载点. 2.mount - ...
- 【MyBatis学习15】MyBatis的逆向工程生成代码
1. 什么是逆向工程 mybatis的一个主要的特点就是需要程序员自己编写sql,那么如果表太多的话,难免会很麻烦,所以mybatis官方提供了一个逆向工程,可以针对单表自动生成mybatis执行所需 ...
- C# t4模版引擎笔记 引入外部dll
<#@ assembly name="D:\Documents\Downloads\Util\Util\bin\Debug\Util.dll" #> <#@ im ...
- 锁定窗口,禁止更新的win32函数
[DllImport("user32.dll", EntryPoint = "LockWindowUpdate", SetLastError = true, E ...
- Retrofit2和RxJava配合使用Demo
和Retrofit2单独使用有一些区别 首先,同样写个interface,这里是GitHubService.java,我们这次要实现获取官方提供的测试接口的数据 public interface Gi ...
- POJ 3561 Pseudographical recognizer
[题意简述]:矩阵中除了'.'仅仅能出现一种符号.是这些之中的一个'‑', '|', '\', or '/',并且就是当除了'.'之外还仅仅有一种符号时.这个符号还必须连成一条直线,否则就是错的,这个 ...
- Chap 2 Representing and Manipulating Information (CS:APP)
-------------------------------------------------------------------------------------------------- A ...
- Android JNI和NDK学习(03)--动态方式实现JNI(转)
本文转自:http://www.cnblogs.com/skywang12345/archive/2013/05/23/3092491.html 前面总结了静态实现JNI的方法,本文介绍如何动态实现J ...
- angularjs 可以加入html标签方法------ng-bind-html的用法总结(2)
angular-ngSanitize模块-$sanitize服务详解 本篇主要讲解angular中的$sanitize这个服务.此服务依赖于ngSanitize模块. 要学习这个服务,先要了解另一个指 ...
- c++ telescoping constructor is NOT supported until c++11
Telescoping constructor: see Effective Java 2nd Edition Item 2 If you want to use telescoping constr ...