题目链接: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)的更多相关文章

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

    题目链接:http://codeforces.com/contest/597/problem/C 思路:dp[i][j]表示长度为i,以j结尾的上升子序列,则有dp[i][j]= ∑dp[i-1][k ...

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

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

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

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

  4. hdu 3030 Increasing Speed Limits (离散化+树状数组+DP思想)

    Increasing Speed Limits Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  5. hdu 2227(树状数组+dp)

    Find the nondecreasing subsequences Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/3 ...

  6. hdu 4991(树状数组+DP)

    Ordered Subsequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  7. hdu 4622 Reincarnation trie树+树状数组/dp

    题意:给你一个字符串和m个询问,问你l,r这个区间内出现过多少字串. 连接:http://acm.hdu.edu.cn/showproblem.php?pid=4622 网上也有用后缀数组搞得. 思路 ...

  8. HDU 6348 序列计数 (树状数组 + DP)

    序列计数 Time Limit: 4500/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Subm ...

  9. [Codeforces261D]Maxim and Increasing Subsequence——树状数组+DP

    题目链接: Codeforces261D 题目大意:$k$次询问,每次给出一个长度为$n$的序列$b$及$b$中的最大值$maxb$,构造出序列$a$为$t$个序列$b$连接而成,求$a$的最长上升子 ...

随机推荐

  1. Asp.Net验证码3

    using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System. ...

  2. POJ 2395 Out of Hay 草荒 (MST,Kruscal,最小瓶颈树)

    题意:Bessie要从牧场1到达各大牧场去,他从不关心他要走多远,他只关心他的水袋够不够水,他可以在任意牧场补给水,问他走完各大牧场,最多的一次需要多少带多少单位的水? 思路:其实就是要让所带的水尽量 ...

  3. Javaweb里面的filter,listener,servlet

    Filter 1Filter是什么:是过滤器简称 2Filter有什么作用:在filter中可以得到代表用户请求和响应的request.response对象,因此在编程中可以使用Decorator(装 ...

  4. Android堆栈分析

    在开发中,与界面跳转联系比较紧密的概念是Task(任务)和Back Stack(回退栈).activity的启动模式会影响Task和Back Stack的状态, 进而影响用户体验.除了启动模式之外,I ...

  5. IOS 单例 创建方式

    @implementation Me static Car *sharedInstance= nil;//声明一个静态对象引用并赋为nil +(Me *) sharedInstance//声明类方法( ...

  6. object does not contain a definition for get_range

      原因[1] 在VS2012中调用COM Interop DLL操作Excel通过get_Range去获取Range时,会发生Object does not contain a definition ...

  7. Android中垃圾回收日志信息

    原因 GC_CONCURRENTfreed 178K, 41% free 3673K/6151K, external 0K/0K, paused 2ms+2msGC_EXPLICITfreed 6K, ...

  8. ASCII和16进制

    所谓的ASCII和16进制都只是概念上的东西,在计算机中通通是二进制 转换应该是输出的转换,同样是一个数,在计算机内存中表示是一样的,只是输出不一样ASCII是针对字符的编码,几乎是键盘上的字符的编码 ...

  9. 改进duilib的richedit控件的部分功能

    转载请说明原出处,谢谢~~:http://blog.csdn.net/zhuhongshu/article/details/41208207 如果要使用透明异形窗体功能,首先要改进duilib库让他本 ...

  10. xp的虚拟机如何访问本地主机上的文件

    1.选中虚拟机,右键选择Settings,在options选项卡里选择Shared Folders,然后在右边设置要共享的文件夹. 2.power on 虚拟机,然后在虚拟机的VM菜单中,选择“Ins ...