【题目链接】:http://codeforces.com/problemset/problem/314/C

【题意】



让你从n个元素的数组中选出所有的不同的非递减子数列;

然后计算比这个子数列小的和它的长度一样长的数列的个数;

“小”的定义在题目里有说;

【题解】



设dp[i]表示以i作为非递减子数列的最后一个数的比它小的数列的个数;

则有递推式

dp[i] = (dp[1]+dp[2]+…+dp[i])*i+i;

写个树状数组,来快速求和就好;

要写出原数组,维护原数组;

不然求dp[i]比较麻烦;

最后输出∑dpi就好



【Number Of WA】



1(数组开小了)



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e6;
const int N1 = 1e5;
const int MOD = 1e9+7; struct BIT{
LL a[N+10];
int lowbit(int x){
return x&(-x);
} void add(int x,LL y){
while (x<=N){
a[x] = (a[x]+y)%MOD;
x+=lowbit(x);
}
} LL sum(int x){
LL temp = 0;
while (x>0){
temp = (temp+a[x])%MOD;
x-=lowbit(x);
}
return temp;
}
}c; int n;
LL dp[N+10]; int main(){
//Open();
Close();
cin >> n;
rep1(i,1,n){
int x;
cin >> x;
LL temp = (c.sum(x)*x + x)%MOD;
c.add(x,(temp-dp[x]+MOD)%MOD);
dp[x] = temp;
}
cout << c.sum(N) << endl;
return 0;
}

【codeforces 314C】Sereja and Subsequences的更多相关文章

  1. 【codeforces 367C】Sereja and the Arrangement of Numbers

    [题目链接]:http://codeforces.com/problemset/problem/367/C [题意] 我们称一个数列a[N]美丽; 当且仅当,数列中出现的每一对数字都有相邻的. 给你n ...

  2. 【22.48%】【codeforces 689D】Friends and Subsequences

    time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...

  3. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  4. 【codeforces 803F】Coprime Subsequences

    [题目链接]:http://codeforces.com/contest/803/problem/F [题意] 给你一个序列; 问你这个序列里面有多少个子列; 且这个子列里面的所有数字互质; [题解] ...

  5. 【codeforces 766A】Mahmoud and Longest Uncommon Subsequence

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  7. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  8. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  9. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

随机推荐

  1. HDU 2049 不容易系列之(4)——考新郎( 错排 )

    链接:传送门 思路:错排水题,从N个人中选出M个人进行错排,即 C(n,m)*d[m] 补充:组合数C(n,m)能用double计算吗?第二部分有解释 Part 1. 分别求出来组合数的分子和分母然后 ...

  2. STM32CubeMx的使用分享

    1. 新建立工程(以F103ZET6为例) 2. 配置引脚(以PA0为例)   3. 配置外设(以串口为例) 4. 配置时钟 5. 外设.GPIO.中断初始化 6. 生成工程 7. 添加自己的代码 8 ...

  3. (转载)spring 之间的远程调用-Spring Http调用的实现

    原文:https://www.cnblogs.com/lewisat/p/6132082.html 1:Spring Http设计思想 最近在研究公司自己的一套rpc远程调用框架,看到其内部实现的设计 ...

  4. fensorflow 安装报错 DEPENDENCY ERROR

    1.错误信息 DEPENDENCY ERROR The target you are trying to run requires an OpenSSL implementation. Your sy ...

  5. 使用hbase遇到的问题

    1.在使用hbase的时候 有很多问题,其中一个 使用sqoop import 从mysql 向hbase导入数据,报错:Error: java.lang.RuntimeException: Coul ...

  6. Mybatis动态代理实现函数调用

    如果我们要使用MyBatis进行数据库操作的话,大致要做两件事情: 1. 定义DAO接口 在DAO接口中定义需要进行的数据库操作. 2. 创建映射文件 当有了DAO接口后,还需要为该接口创建映射文件. ...

  7. SQL SERVER-约束

    NOT NULL - 指示某列不能存储 NULL 值. UNIQUE - 保证某列的每行必须有唯一的值. PRIMARY KEY - NOT NULL 和 UNIQUE 的结合.确保某列(或两个列多个 ...

  8. android选择图片或拍照图片上传到server(包含上传參数)

    在9ria论坛看到的.还没測试,先Mark与大家分享一下. 近期要搞一个项目,须要上传相冊和拍照的图片.不负所望,最终完毕了! 只是须要说明一下,事实上网上非常多教程拍照的图片.都是缩略图不是非常清晰 ...

  9. 【LeetCode】Palindrome Partitioning 解题报告

    [题目] Given a string s, partition s such that every substring of the partition is a palindrome. Retur ...

  10. Pocket英语语法---四、should的同义词是谁

    Pocket英语语法---四.should的同义词是谁 一.总结 一句话总结:should表示劝告,建议,命令,其同义词是ought to,should强调主观看法,ought to强调客观要求.在疑 ...