题目链接: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. Android udev /dev 设备节点权限

    /************************************************************************* * Android udev /dev 设备节点权 ...

  2. python练习程序(c100经典例16)

    题目: 输入两个正整数m和n,求其最大公约数和最小公倍数. def foo(a,b): if a<b: (a,b)=(b,a) aa=a; bb=b; while b!=0: tmp=a%b; ...

  3. Search in Rotated Sorted Array II

    Question: Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? W ...

  4. uimodalpresentationformsheet resize ios7

    CROHomeCRAAddController *temp =[[CROHomeCRAAddControlleralloc] init]; temp.modalTransitionStyle = UI ...

  5. hadoop——在命令行下编译并运行map-reduce程序 2

     hadoop map-reduce程序的编译需要依赖hadoop的jar包,我尝试javac编译map-reduce时指定-classpath的包路径,但无奈hadoop的jar分布太散乱,根据自己 ...

  6. nginx upstream的分配方式

    1.轮询(默认) 每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除. 2.weight 指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况. 例 ...

  7. [转]linux系统的7种运行级别

    转自:http://blog.chinaunix.net/uid-22746363-id-383989.html Linux系统有7个运行级别(runlevel)运行级别0:系统停机状态,系统默认运行 ...

  8. 使用clipboard.js复制页面内容到剪切板

    最近在做一个的智能客服Web端浏览器应用,其中有一项需求是客户在获取系统返回的 答案后点击“复制答案”按钮将答案复制到系统剪切板.本以为这是一个小case,但是发现如果 要对各种主流浏览器都有良好的兼 ...

  9. 提供给开发者 10 款最好的 Python IDE

    Python 非常易学,强大的编程语言.Python 包括高效高级的数据结构,提供简单且高效的面向对象编程. Python 的学习过程少不了 IDE 或者代码编辑器,或者集成的开发编辑器(IDE).这 ...

  10. 【C#】用C#通过读取数据库方式读取CSV文件

    using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; names ...