Codeforces 597C. Subsequences (树状数组+dp)
题目链接:http://codeforces.com/contest/597/problem/C
给你n和数(1~n各不同),问你长为k+1的上升自序列有多少。
dp[i][j] 表示末尾数字为i 长度为j的上升子序列个数,但是dp数组是在树状数组的update函数中进行更新。
update(i, val, j)函数表示在i的位置加上val,更新dp[i][j]。
sum(i, j)就是求出末尾数字小于等于i 且长度为j的子序列有多少个。
//#pragma comment(linker, "/STACK:102400000, 102400000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef __int64 LL;
typedef pair <int, int> P;
const int N = 1e5 + ;
int a[N], n;
LL dp[N][]; void update(int i, LL val, int c) {
for( ; i <= n; i += (i&-i))
dp[i][c] += val;
} LL sum(int i, int c) {
LL s = ;
for( ; i >= ; i -= (i&-i))
s += dp[i][c];
return s;
} LL Cnm(LL a, LL b) {
if(b > a)
return ;
LL res1 = , res2 = ;
for(LL i = ; i < b; ++i) {
res1 *= (a - i);
res2 *= (b - i);
}
return res1 / res2;
} int main()
{
int k;
scanf("%d %d", &n, &k);
k++;
LL res = ;
for(int i = ; i <= n; ++i) {
scanf("%d", a + i);
for(int j = ; j <= k; ++j) {
if(j == ) {
update(a[i], , j);
continue;
}
LL temp = sum(a[i] - , j - );
if(temp) {
update(a[i], temp, j);
}
}
}
printf("%lld\n", sum(n, k));
return ;
}
Codeforces 597C. Subsequences (树状数组+dp)的更多相关文章
- codeforces 597C (树状数组+DP)
题目链接:http://codeforces.com/contest/597/problem/C 思路:dp[i][j]表示长度为i,以j结尾的上升子序列,则有dp[i][j]= ∑dp[i-1][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 ...
- hdu 3030 Increasing Speed Limits (离散化+树状数组+DP思想)
Increasing Speed Limits Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java ...
- hdu 2227(树状数组+dp)
Find the nondecreasing subsequences Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/3 ...
- hdu 4991(树状数组+DP)
Ordered Subsequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 4622 Reincarnation trie树+树状数组/dp
题意:给你一个字符串和m个询问,问你l,r这个区间内出现过多少字串. 连接:http://acm.hdu.edu.cn/showproblem.php?pid=4622 网上也有用后缀数组搞得. 思路 ...
- HDU 6348 序列计数 (树状数组 + DP)
序列计数 Time Limit: 4500/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Subm ...
- [Codeforces261D]Maxim and Increasing Subsequence——树状数组+DP
题目链接: Codeforces261D 题目大意:$k$次询问,每次给出一个长度为$n$的序列$b$及$b$中的最大值$maxb$,构造出序列$a$为$t$个序列$b$连接而成,求$a$的最长上升子 ...
随机推荐
- BZOJ 1176 MOKIA
cdq分治. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm ...
- BZOJ 1787 紧急集合
LCA.注意细节. #include<iostream> #include<cstdio> #include<cstring> #include<algori ...
- 文件IO
在unix世界中视一切为文件,无论最基本的文本文件还是网络设备或是u盘,在内核看来它们的本质都是一样的.大多数文件IO操作只需要用到5个函数:open . read . write . lseek 以 ...
- php 获取指定日期所在月份的最后一天
本文引用来自 http://hi.baidu.com/yflife/item/fd00ef142c5967fcdceeca84 php 获取指定月最后一天: <?phpfunction gett ...
- Android应用性能优化之使用SQLiteStatement优化SQLite操作
平常在做Android数据库操作时,都是用的execSQL之个方法. 今天偶然发现了SQLiteStatement这个类.让我想起了在做Java Web开发写JDBC的代码时Prestatement这 ...
- PHP中最容易忘记的一些知识点总结
1.require 和require_once 区别: 前者遇到即包含文件,后者会判断是否已经包含过了,如果包含过了,则不再包含文件.一可以节省资源,二可以避免重复定义的错误. 2.include 和 ...
- myeclipse 打开xml jsp页面慢 有时候会自动退出
Myeclipse默认打开文件的方式是 jsp design,每次双击或者使用Ctrl+Shift+R打开 就会用这个打开 ,太慢了而且多次导致Myeclipse挂掉.可以通过以下的方式转化成你想要的 ...
- SDE+ORACLE优化配置
原文 SDE+ORACLE优化配置 SDE的性能取决于: 首先操作系统的性能:其次是Oracle的性能,再次是SDE的性能. 第一:操作系统,无非是内存.CPU.带宽等. 可以有待提高的地方:第一.硬 ...
- 【C++】统计代码覆盖率(三)
报告集成到jenkins才是最终目的,因此又进行了部分资料查找,得到html和xml报告集成jenkins的配置如下: 一 集成html报告 这种方式集成在你已经用gcov+lcov生成了html报告 ...
- CString类Format()的用法 .xml
pre{ line-height:1; color:#9f1d66; background-color:#f0f0f0; font-size:16px;}.sysFunc{color:#5d57ff; ...