题意:给定一个N个数的数列,求所有不同不下降子序列的乘积之和,其中不同指的是组成它的数字和长度不完全相同

n (1 ≤ n ≤ 10^5) a[i]<=10^6

思路:考虑DP。设DP[a[i]]为最后一位为a[i]时所有序列的积之和,则dp[a[i]]=a[i]+sigma(dp[a[j]]) *a[i] (a[j]<=a[i],j<i)

后一部分可以用树状数组计算

为了去除最后一位相同的序列比如1 2 2 这个序列中1 2这个子序列只能算一遍

要强行去掉原来最后一位为a[i]的序列

 const mo=;
var dp:array[..]of int64;
n,i:longint;
s1,s2,t,ans,x:int64; function lowbit(x:longint):longint;
begin
exit(x and (-x));
end; function sum(x:longint):int64;
var t:int64;
begin
t:=;
while x> do
begin
t:=(t+dp[x]) mod mo;
x:=x-lowbit(x);
end;
exit(t);
end; procedure add(x,s:longint);
begin
while x<= do
begin
dp[x]:=(dp[x]+s) mod mo;
x:=x+lowbit(x);
end;
end; begin
//assign(input,'314C.in'); reset(input);
//assign(output,'314C.out'); rewrite(output);
readln(n);
for i:= to n do
begin
read(x);
s1:=sum(x); s2:=sum(x-);
t:=(s1+) mod mo*(x mod mo) mod mo;
t:=(t-(s1-s2) mod mo) mod mo;
t:=(t+mo) mod mo;
add(x,t);
ans:=(ans+t) mod mo;
end;
writeln(ans);
//close(input);
//close(output);
end.

【CF314C】Sereja and Subsequences(DP,树状数组)的更多相关文章

  1. CodeForces - 314C Sereja and Subsequences (树状数组+dp)

    Sereja has a sequence that consists of n positive integers, a1, a2, ..., an. First Sereja took a pie ...

  2. codeforces 597C C. Subsequences(dp+树状数组)

    题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...

  3. HDU 2227 Find the nondecreasing subsequences (DP+树状数组+离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2227 Find the nondecreasing subsequences             ...

  4. CF 314C Sereja and Subsequences(树状数组)

    题目链接:http://codeforces.com/problemset/problem/314/C 题意:给定一个数列a.(1)写出a的不同的所有非下降子列:(2)定义某个子列的f值为数列中各个数 ...

  5. 树形DP+树状数组 HDU 5877 Weak Pair

    //树形DP+树状数组 HDU 5877 Weak Pair // 思路:用树状数组每次加k/a[i],每个节点ans+=Sum(a[i]) 表示每次加大于等于a[i]的值 // 这道题要离散化 #i ...

  6. bzoj 1264 [AHOI2006]基因匹配Match(DP+树状数组)

    1264: [AHOI2006]基因匹配Match Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 793  Solved: 503[Submit][S ...

  7. 【bzoj2274】[Usaco2011 Feb]Generic Cow Protests dp+树状数组

    题目描述 Farmer John's N (1 <= N <= 100,000) cows are lined up in a row andnumbered 1..N. The cows ...

  8. 奶牛抗议 DP 树状数组

    奶牛抗议 DP 树状数组 USACO的题太猛了 容易想到\(DP\),设\(f[i]\)表示为在第\(i\)位时方案数,转移方程: \[ f[i]=\sum f[j]\;(j< i,sum[i] ...

  9. HDU2227Find the nondecreasing subsequences(树状数组+DP)

    题目大意就是说帮你给出一个序列a,让你求出它的非递减序列有多少个. 设dp[i]表示以a[i]结尾的非递减子序列的个数,由题意我们可以写出状态转移方程: dp[i] = sum{dp[j] | 1&l ...

  10. CodeForces - 597C Subsequences 【DP + 树状数组】

    题目链接 http://codeforces.com/problemset/problem/597/C 题意 给出一个n 一个 k 求 n 个数中 长度为k的上升子序列 有多少个 思路 刚开始就是想用 ...

随机推荐

  1. 在2d游戏中常用的向量方式

    function cc.exports.VectorRotateByAngle(vector,angle)--计算向量旋转后的向量,angle:正数逆时针,负输顺时针 angle = angle*ma ...

  2. GoogleTest 之路3-Mocking Framework

    当你写一个原型或者测试的时候,依赖整个object 是不可行和明智的.一个 mock object和 real object 有同样的接口(所以它可以像同一个使用),但是让你在运行时进行指定它应该如何 ...

  3. destoon手机端mobileurl函数增加城市分类参数

    mobileurl函数在include/global.func.php 858行 共四个参数,moduleid-模型id,catid-分类id,itemid -文章id,page-页码 functio ...

  4. jQuery plugin : bgStretcher 背景图片切换效果插件

    转自:http://blog.dvxj.com/pandola/jQuery_bgStretcher.html bgStretcher 2011 (Background Stretcher)是一个jQ ...

  5. 创建 Django 步骤

    1.创建项目 django-admin startproject 项目名称 2.创建APP python manage.py startapp app名称 3.修改settings.py文件 3.1设 ...

  6. yagmail 邮箱的使用

    文章来源:GITHub:https://github.com/kootenpv/yagmail 安装 pip3 install yagmail pip3 install keyring 简单例子 im ...

  7. Windows下新建多级文件夹

    使用system函数调用系统命令"md" 注意:字符串变量的话赋值时要使用双斜杠"\\": system("md C:\\newfolder\\&qu ...

  8. 为工程添加上下文菜单(ContextMenu)

    上下文菜单大多数情况下都是为ListView中的Item添加的,长按2S左右跳出菜单,添加上下文菜单必须重写活动中的onCreateContextMenu()方法和onContextItemSelec ...

  9. BZOJ 5390: [Lydsy1806月赛]糖果商店

    F[i][j]表示总重量为i,最上面那个盒子中糖果种类为j的方案数 每次新加一个盒子,或者在原来盒子中加入一个糖 F[i][0]为中间状态,优化转移(表示最上面那个盒子不能加糖果) #include& ...

  10. apache 虚拟主机配置(根据不同的域名映射到不同网站)

    最近弄了台香港服务器做测试,Web服务器软件用的是Apache2.2,机器只有一台,ip只有一个,但是想测试几个站点,于是尝试了下Apache的虚拟主机配置.之前已经写过一篇博文了——<Apac ...