codeforces 597C (树状数组+DP)
题目链接:http://codeforces.com/contest/597/problem/C
思路:dp[i][j]表示长度为i,以j结尾的上升子序列,则有dp[i][j]= ∑dp[i-1][k](1<=k<j),由于要求前缀和,可以用树状数组优化
#include<bits/stdc++.h>
#define lowbit(x) x&(-x)
typedef long long ll;
const int N=1e5+3;
ll dp[12][N];
using namespace std;
void update(int i,int pos,ll num,int n)
{
while(pos <= n)
{
dp[i][pos] += num;
pos += lowbit(pos);
}
}
ll sum(int i,int pos)
{
ll res=0;
while(pos)
{
res += dp[i][pos];
pos -= lowbit(pos);
}
return res;
}
int main()
{
int n,k,x;
scanf("%d %d",&n,&k);
for(int i = 1 ;i <= n ;i++)
{
scanf("%d",&x);
update(1,x,1,n);
for(int j = 2 ;j <= k+1 ;j++)
update(j,x,sum(j-1,x-1),n);
}
printf("%I64d\n",sum(k+1,n));
return 0;
}
codeforces 597C (树状数组+DP)的更多相关文章
- Codeforces 597C. Subsequences (树状数组+dp)
题目链接:http://codeforces.com/contest/597/problem/C 给你n和数(1~n各不同),问你长为k+1的上升自序列有多少. dp[i][j] 表示末尾数字为i 长 ...
- CodeForces - 314C Sereja and Subsequences (树状数组+dp)
Sereja has a sequence that consists of n positive integers, a1, a2, ..., an. First Sereja took a pie ...
- HDU 3333 | Codeforces 703D 树状数组、离散化
HDU 3333:http://acm.hdu.edu.cn/showproblem.php?pid=3333 这两个题是类似的,都是离线处理查询,对每次查询的区间的右端点进行排序.这里我们需要离散化 ...
- hdu 4622 Reincarnation trie树+树状数组/dp
题意:给你一个字符串和m个询问,问你l,r这个区间内出现过多少字串. 连接:http://acm.hdu.edu.cn/showproblem.php?pid=4622 网上也有用后缀数组搞得. 思路 ...
- HDU2227Find the nondecreasing subsequences(树状数组+DP)
题目大意就是说帮你给出一个序列a,让你求出它的非递减序列有多少个. 设dp[i]表示以a[i]结尾的非递减子序列的个数,由题意我们可以写出状态转移方程: dp[i] = sum{dp[j] | 1&l ...
- 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$的最长上升子 ...
- 【XSY2727】Remove Dilworth定理 堆 树状数组 DP
题目描述 一个二维平面上有\(n\)个梯形,满足: 所有梯形的下底边在直线\(y=0\)上. 所有梯形的上底边在直线\(y=1\)上. 没有两个点的坐标相同. 你一次可以选择任意多个梯形,必须满足这些 ...
- hdu5489 树状数组+dp
2015-10-06 21:49:54 这题说的是个给了一个数组,然后删除任意起点的一个连续的L个数,然后求最长递增子序列<是递增,不是非递减>,用一个树状数组维护一下就ok了 #incl ...
随机推荐
- Word Search [LeetCode]
Problem Description: http://oj.leetcode.com/problems/word-search/ Basic idea: recursively go forward ...
- Redis(7)Creating and Using Cluster Mode
1. DocumentsCluster will not support SELECT, it only contains database 0.All the nodes use TCP bus a ...
- linux shell中,单引号、 双引号,反引号(``),$()的区别
一.单引号和双引号 首先,单引号和双引号,都是为了解决中间有空格的问题. 空格在linux中时作为一个很典型的分隔符,比如 string1=this is a string,这样执行会报错.为了避免这 ...
- synchronized和static synchronized的比较
群里讨论的一个问题,网上别人已经贴出了很详细的说明,这里补充记录下,后面加入个人测试代码. 起因:1月份的时候看群里讨论一道问题,问题内容如下: 一个日本作者-结成浩的<java多线程设计模式& ...
- hihocode ---1032
#include<iostream> #include<cstring> #include<cstdio> using namespace std; + ; ]; ...
- 第三方开源水面波浪波形view:WaveView
一个比较有趣的Android第三方开源波形view:WaveView,这种WaveView在一些常见的APP开发中,以水面波浪波形的形象的生动展示手机还剩余多少电量,存储容量还有多少等,比较形象直观生 ...
- dancing link模板
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #i ...
- 编码为multipart/form-data自定义类型(包括文件)如何自动绑定到webapi的action的参数里
application/x-www-form-urlencoded与 multipart/form-data: Fom表单中如果没有type=file的控件,用默认的application/x-www ...
- python交互模式下cp65001异常
unknown encoding: cp65001异常 python安装后进入命令行交互模式,输入任何代码都报unknown encoding: cp65001异常 需要将编码(UTF-8)修改为 简 ...
- TOP 10开源的推荐系统简介
最近这两年推荐系统特别火,本文搜集整理了一些比较好的开源推荐系统,即有轻量级的适用于做研究的SVDFeature.LibMF.LibFM等,也有重量级的适用于工业系统的 Mahout.Oryx.Eas ...