Codeforces 597C Subsequences 【树状数组优化DP】
来源:互联网 发布:iphonex监控预约软件 编辑:程序博客网 时间:2024/04/30 03:58
题意:给定n个元素的序列,让你求出长度为k的上升子序列个数。
思路:和CCPC那道题很像,直接用个树状数组转移就好了。时间复杂度O(nlog(n)k)。
AC代码:
#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <vector>#define INF 0x3f3f3f3f#define eps 1e-8#define MAXN (100000+10)#define MAXM (50000000)#define Ri(a) scanf("%d", &a)#define Rl(a) scanf("%lld", &a)#define Rf(a) scanf("%lf", &a)#define Rs(a) scanf("%s", a)#define Pi(a) printf("%d\n", (a))#define Pf(a) printf("%lf\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define W(a) while(a--)#define CLR(a, b) memset(a, (b), sizeof(a))#define MOD 1000003#define LL long long#define lson o<<1, l, mid#define rson o<<1|1, mid+1, r#define ll o<<1#define rr o<<1|1using namespace std;struct Node{ int val, id;};Node num[MAXN];bool cmp(Node a, Node b){ if(a.val != b.val) return a.val < b.val; else return a.id > b.id;}int n, k;LL dp[12][MAXN];int lowbit(int x){ return x & (-x);}void update(int x, int id, LL d){ while(x <= n) { dp[id][x] += d; x += lowbit(x); }}LL sum(int x, int id){ LL s = 0; while(x > 0) { s += dp[id][x]; x -= lowbit(x); } return s;}int main(){ Ri(n); Ri(k); for(int i = 1; i <= n; i++) Ri(num[i].val), num[i].id = i; sort(num+1, num+n+1, cmp); CLR(dp, 0); for(int i = 1; i <= n; i++) { for(int j = 1; j <= min(k+1, i); j++) { if(j == 1) update(num[i].id, j, 1); else update(num[i].id, j, sum(num[i].id-1, j-1)); } } Pl(sum(n, k+1)); return 0;}
0 0
- Codeforces 597C Subsequences 【树状数组优化DP】
- Codeforces 597C Subsequences dp + 树状数组
- Subsequences CodeForces - 597C 树状数组 + dp
- Codeforces 597C Subsequences【Dp+二维树状数组】
- codeforces-597C-Subsequences【树状数组】
- 【Codeforces 597C】【DP 树状数组优化】Subsequences 【n个不同数,长度为k+1的LIS数】
- 597C. Subsequences【DP】【树状数组】
- Codeforces Testing Round #12C - Subsequences (dp+树状数组优化)
- 【Codeforces Testing Round 12C】【DP 树状数组优化】Subsequences n个不同数,长度为m的LIS数
- [dp+树状数组优化] CF597C. Subsequences
- Codeforces 597C(树状数组 + dp)
- codeforces 597C (树状数组+DP)
- CodeForces 597C 树状数组 dp
- Codeforce 597C(dp+树状数组优化)
- hdoj 2227 Find the nondecreasing subsequences 【树状数组优化dp】
- lightoj 1085 - All Possible Increasing Subsequences 【树状数组优化dp】
- CF - 314C - Sereja and Subsequences(树状数组+dp)
- 【Codeforces 597C】 Subsequences - DP 主席树
- MATLAB和C/C++混合编程实现图像处理(一)
- 创建网页版UFT脚本技术点
- LightOJ 1036 - A Refining Company(dp)
- 【Android】Android项目中R文件找不到怎么处理?
- 第十三章 RememberMe
- Codeforces 597C Subsequences 【树状数组优化DP】
- 第十四章 SSL
- 遍历一个文件夹下面的文件(半原创)
- 在64位Ubuntu 14.04 LTS 中安装praat
- [leetcode 19] Remove Nth Node From End of List
- 第十五章 单点登录
- 第十六章 综合实例
- Java 声明变量名的规则
- Java学习中遇到的问题01_IO流