题目和南阳那道题一样链接http://www.cnblogs.com/zzuli2sjy/p/4943774.html

代码:

 1 #include<stdio.h>
2 #include<algorithm>
3 #include<string.h>
4 #include<stdlib.h>
5 #include<iostream>
6 #include<map>
7 typedef long long ll;
8 const ll N=1e5+5;
9 ll dp[20][N];
10 ll a[N];
11 ll bit[N];
12 int found(int n,int m,ll k);
13 ll sum(int i);
14 void add(int i,ll x,int t);
15 using namespace std;
16 int main(void)
17 {
18 ll i,j,k,p,q;
19 while(scanf("%I64d %I64d",&k,&p)!=EOF)
20 {
21 memset(dp,0,sizeof(dp));
22 memset(bit,0,sizeof(bit));
23 for(i=0; i<k; i++)
24 {
25 scanf("%I64d",&a[i]);
26 }int cnt=k;
27 for(i=0; i<k; i++)
28 {
29 dp[1][i]=1;
30 }
31 for(i=2; i<=p+1; i++)
32 {
33 memset(bit,0,sizeof(bit));
34 for(j=i-2; j<k; j++)
35 {
36 dp[i][j]=sum(a[j]-1);
37 add(a[j],dp[i-1][j],cnt);
38 }
39
40 }
41 ll sum=0;
42 for(i=0; i<k; i++)
43 {
44 sum+=dp[p+1][i];
45
46 }
47 printf("%I64d\n",sum);
48 }
49 return 0;
50 }
51 ll sum(int i)
52 {
53 ll s=0;
54 while(i>0)
55 {
56 s+=bit[i];
57 i-=(i&-i);
58 }
59 return s;
60 }
61
62 void add(int i,ll x,int t)
63 {
64 while(i<=t)
65 {
66 bit[i]+=x;
67 i+=(i&-i);
68 }
69 }

codeforce 597C-Subsequences(dp+树状数组)的更多相关文章

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

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

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

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

  3. CodeForces - 597C Subsequences (树状数组+动态规划)

    For the given sequence with n different elements find the number of increasing subsequences with k + ...

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

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

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

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

  6. 【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 ...

  7. 奶牛抗议 DP 树状数组

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

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

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

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

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

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

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

随机推荐

  1. 28-Merge Two Sorted Lists

    easy 21. Merge Two Sorted Lists Merge two sorted linked lists and return it as a new list. The new l ...

  2. 移动测试(web和app)及app测试实战

    移动测试androidiosapp上 原生GUI 混合应用H5 web端兼容性浏览器测试需要的内容:safari 浏览器edge浏览器ie11浏览器firefox浏览器chrome浏览器 国内360浏 ...

  3. 大数据学习day23-----spark06--------1. Spark执行流程(知识补充:RDD的依赖关系)2. Repartition和coalesce算子的区别 3.触发多次actions时,速度不一样 4. RDD的深入理解(错误例子,RDD数据是如何获取的)5 购物的相关计算

    1. Spark执行流程 知识补充:RDD的依赖关系 RDD的依赖关系分为两类:窄依赖(Narrow Dependency)和宽依赖(Shuffle Dependency) (1)窄依赖 窄依赖指的是 ...

  4. pyqt5 改写函数

    重新改写了keyPressEvent() class TextEdit(QTextEdit): def __init__(self): QtWidgets.QTextEdit.__init__(sel ...

  5. Linux服务器---xopps

    XOOPS XOOPS是一款用php制作的开源网站管理系统,可用于构建各种网络站点. 1.下载XOOPS软件(https://xoops.org/) 2.将XOOPS软件中的htdocs文件夹拷贝到a ...

  6. zabbix之源码安装

    #:官网地址 https://www.zabbix.com/documentation/4.0/zh/manual/installation/install #:解压并创建用户 root@ubuntu ...

  7. 使用mybatis更新数据时 时间字段的值自动更新

    1.debug打印出来执行的sql语句发现并没有修改时间的字段,最后发现是设计表时勾选了根据当前时间戳更新..... 去掉该字段的根据当前时间戳更新语句: alter table tableName ...

  8. js - 日期、时间 Date对象方法

    Date 是 JS 内置的日期构造函数 var d = new Date();  // 这个是系统当前时间的日期实例 d.getYear(); // 返回 d 实例年份 - 1900 d.getFul ...

  9. 下载requests库

    下载requests库 第一步:找到python的安装位置,可以从下面的图中找到 第二步:复制scripts文件夹的位置 第三步:win+r打开cmd cd 到scripts文件夹的位置 第四步:运行 ...

  10. C++STL标准库学习笔记(三)multiset

    C++STL标准库学习笔记(三)multiset STL中的平衡二叉树数据结构 前言: 在这个笔记中,我把大多数代码都加了注释,我的一些想法和注解用蓝色字体标记了出来,重点和需要关注的地方用红色字体标 ...