【题目链接】: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(数组开小了)



【完整代码】

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,m,rt<<1
  4. #define rson m+1,r,rt<<1|1
  5. #define LL long long
  6. #define rep1(i,a,b) for (int i = a;i <= b;i++)
  7. #define rep2(i,a,b) for (int i = a;i >= b;i--)
  8. #define mp make_pair
  9. #define pb push_back
  10. #define fi first
  11. #define se second
  12. #define ms(x,y) memset(x,y,sizeof x)
  13. #define Open() freopen("F:\\rush.txt","r",stdin)
  14. #define Close() ios::sync_with_stdio(0),cin.tie(0)
  15. typedef pair<int,int> pii;
  16. typedef pair<LL,LL> pll;
  17. const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
  18. const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
  19. const double pi = acos(-1.0);
  20. const int N = 1e6;
  21. const int N1 = 1e5;
  22. const int MOD = 1e9+7;
  23. struct BIT{
  24. LL a[N+10];
  25. int lowbit(int x){
  26. return x&(-x);
  27. }
  28. void add(int x,LL y){
  29. while (x<=N){
  30. a[x] = (a[x]+y)%MOD;
  31. x+=lowbit(x);
  32. }
  33. }
  34. LL sum(int x){
  35. LL temp = 0;
  36. while (x>0){
  37. temp = (temp+a[x])%MOD;
  38. x-=lowbit(x);
  39. }
  40. return temp;
  41. }
  42. }c;
  43. int n;
  44. LL dp[N+10];
  45. int main(){
  46. //Open();
  47. Close();
  48. cin >> n;
  49. rep1(i,1,n){
  50. int x;
  51. cin >> x;
  52. LL temp = (c.sum(x)*x + x)%MOD;
  53. c.add(x,(temp-dp[x]+MOD)%MOD);
  54. dp[x] = temp;
  55. }
  56. cout << c.sum(N) << endl;
  57. return 0;
  58. }

【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. redis 篇 - hash

    hash 可以认为是 python 中的字典 field 不允许重复 string类型的field和value的映射表 每个hash可以存储 232 - 1 键值对(40多亿) 方法 hest key ...

  2. [置顶] 智能家居开源项目 The open Home Automation Bus (openHAB)

    ================================================================================ 2014-05-19 论文的事情太多, ...

  3. HDU 5918 Sequence I

    题目来源:2016 CCPC 长春站 题意:给出两个序列 a[] , b[] ,如果b1,b2....bm能够与aq,aq+p,aq+2p...aq+(m-1)p对应( q+(m-1)p<=n ...

  4. BZOJ 3786 星系探索 (splay+dfs序)

    题目大意:给你一棵树,支持一下三种操作 1.获取某节点到根节点的路径上所有节点的权值和 2.更换某棵子树的父亲 3.某子树内所有节点的权值都增加一个值w 当时想到了splay维护dfs序,查完题解发现 ...

  5. 安装虚拟机和Linux系统

    - 安装虚拟机 点击下载虚拟机 点击下载Linux系统 菜鸟网的Linux系统教程 1.安装虚拟机 在弹出的面板中选择标准--继续. 选择第二个选项,因为我们下载的光盘的镜像,所以直接选择刚才的dvd ...

  6. java.lang.RuntimeException: java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符

    这种情况可能是因为在设置数据库的时候,没有配置数据库的方言,导致sql语句无法被识别. 例如在配置Jfinal的配置文件的时候 如果不配置数据库的方言,默认下它是MySQL的,当使用oracle数据库 ...

  7. Android Java 程序员必备开发工具

    对于Java,有两种截然不同的观点:一种认为Java是最简单功能最强大的编程语言之一,另一种则表示这种编程语言既难用又复杂. 下面这些工具或许功能和作用不同,但是有着一个共同的主旨,那就是——它们都是 ...

  8. NHibernate3剖析:Mapping篇之集合映射基础(3):List映射

    系列引入 NHibernate3.0剖析系列分别从Configuration篇.Mapping篇.Query篇.Session策略篇.应用篇等方面全面揭示NHibernate3.0新特性和应用及其各种 ...

  9. cmd 下命令

    tasklist 查看当前进程 taskkill /? 查看taskkill 的帮助信息 详情 cmd /?  查看cmd详情 color /? 查看颜色详情  比如 color 2 md d:\ji ...

  10. 解决django.db.utils.InternalError: (1049, "Unknown database 'exam_db'")

    先检查seeting数据库配置DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'eaxm_db', ' ...