codeforce 597C-Subsequences(dp+树状数组)

题目和南阳那道题一样链接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+树状数组)的更多相关文章
- codeforces 597C C. Subsequences(dp+树状数组)
题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...
- HDU 2227 Find the nondecreasing subsequences (DP+树状数组+离散化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2227 Find the nondecreasing subsequences ...
- CodeForces - 597C Subsequences (树状数组+动态规划)
For the given sequence with n different elements find the number of increasing subsequences with k + ...
- 树形DP+树状数组 HDU 5877 Weak Pair
//树形DP+树状数组 HDU 5877 Weak Pair // 思路:用树状数组每次加k/a[i],每个节点ans+=Sum(a[i]) 表示每次加大于等于a[i]的值 // 这道题要离散化 #i ...
- bzoj 1264 [AHOI2006]基因匹配Match(DP+树状数组)
1264: [AHOI2006]基因匹配Match Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 793 Solved: 503[Submit][S ...
- 【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 ...
- 奶牛抗议 DP 树状数组
奶牛抗议 DP 树状数组 USACO的题太猛了 容易想到\(DP\),设\(f[i]\)表示为在第\(i\)位时方案数,转移方程: \[ f[i]=\sum f[j]\;(j< i,sum[i] ...
- CodeForces - 597C Subsequences 【DP + 树状数组】
题目链接 http://codeforces.com/problemset/problem/597/C 题意 给出一个n 一个 k 求 n 个数中 长度为k的上升子序列 有多少个 思路 刚开始就是想用 ...
- CodeForces - 314C Sereja and Subsequences (树状数组+dp)
Sereja has a sequence that consists of n positive integers, a1, a2, ..., an. First Sereja took a pie ...
- HDU2227Find the nondecreasing subsequences(树状数组+DP)
题目大意就是说帮你给出一个序列a,让你求出它的非递减序列有多少个. 设dp[i]表示以a[i]结尾的非递减子序列的个数,由题意我们可以写出状态转移方程: dp[i] = sum{dp[j] | 1&l ...
随机推荐
- 关于写SpringBoot+Mybatisplus+Shiro项目的经验分享四:部署到阿里云
框架: SpringBoot+Mybatisplus+Shiro 简单介绍:关于写SpringBoot+Mybatisplus+Shiro项目的经验分享一:简单介绍 阿里云开放必要端口,mysql与t ...
- STM32一些特殊引脚做IO使用的注意事项
1 PC13.PC14.PC15的使用 这三个引脚与RTC复用,<STM32参考手册>中这样描述: PC13 PC14 PC15需要将VBAT与VDD连接,实测采用以下程序驱动4个74HC ...
- HelloWorldModelMBean
package mbeanTest; import java.lang.reflect.Constructor; import javax.management.Descriptor; import ...
- OS开发之Objective-C与JavaScript的交互
UIWebView是iOS最常用的SDK之一,它有一个stringByEvaluatingJavaScriptFromString方法可以将javascript嵌入页面中,通过这个方法我们可以在iOS ...
- zabbix之监控MySQL
#:先配置MySQL的主从 #:安装Percona Monitoring Plugins (地址:https://www.percona.com/downloads/)#:我安在从库,监控哪个就安哪个 ...
- 软件测试人员必备的linux命令
1 目录与文件操作1.1 ls(初级)使用权限:所有人功能 : 显示指定工作目录下之内容(列出目前工作目录所含之档案及子目录). 参数 : -a 显示所有档案及目录 (ls内定将档案名或目录名称开头为 ...
- git 使用https方式进行 pull、push代码免密
由于网络原因我用ssh方法拉取代码每次都提示远程服务连接失败,因此我用了https方式去拉去代码. 这种方式拉取代码每次操作都要输入密码,为了解决这个问题做了一下操作: 在命令行输入 git conf ...
- 使用缓冲流和byte数组,拷贝文件
package com.itcast.demo05.Buffered;import java.io.*;/** * @author newcityman * @date 2019/7/28 - 17: ...
- VectorCAST软件自动化测试方案
VectorCAST 是主要用于对C/C++/Ada程序进行软件自动化测试,并能够在Windows和Linux等多种开发环境下运行.其主要功能包含自动化的单元测试.集 成测试.覆盖率分析.回归测试.代 ...
- Salesforce LWC学习(三十七) Promise解决progress-indicator的小问题
本篇参考:https://developer.salesforce.com/docs/component-library/bundle/lightning-progress-indicator/exa ...