codeforces 597C - Subsequences
枚举子序列的末尾,递推。
方案数:f[i = 以i结尾][k =子序列长度] = sum(f[j][k-1]),j < i。
转移就建立k个BIT。
#include<bits/stdc++.h>
using namespace std; typedef long long ll; const int N = 1e5+, K = ; ll C[K][N]; ll sum(ll C[],int x)
{
ll re = ;
while(x > ){
re += C[x]; x &= x-;
}
return re;
} int n;
void add(ll C[],int x,ll d)
{
while(x <= n){
C[x] += d; x += x&-x;
}
} //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int k;
cin>>n>>k;
if(k == ) { cout<<n; return ;}
k--;
ll ans = ;
for(int i = ,j,x; i < n; i++){
scanf("%d",&x);
ans += sum(C[k],x);
for(j = k; j > ; j--){
add(C[j],x,sum(C[j-],x));
}
add(C[],x,);
}
cout<<ans<<endl;
return ;
}
codeforces 597C - Subsequences的更多相关文章
- Codeforces 597C. Subsequences (树状数组+dp)
题目链接:http://codeforces.com/contest/597/problem/C 给你n和数(1~n各不同),问你长为k+1的上升自序列有多少. dp[i][j] 表示末尾数字为i 长 ...
- CodeForces - 597C Subsequences (树状数组+动态规划)
For the given sequence with n different elements find the number of increasing subsequences with k + ...
- CodeForces - 597C Subsequences 【DP + 树状数组】
题目链接 http://codeforces.com/problemset/problem/597/C 题意 给出一个n 一个 k 求 n 个数中 长度为k的上升子序列 有多少个 思路 刚开始就是想用 ...
- codeforces 497E Subsequences Return
codeforces 497E Subsequences Return 想法 做完这题,学了一些东西. 1.求一个串不同子序列个数的两种方法.解一 解二 2.这道题 \(n\) 很大,很容易想到矩阵加 ...
- codeforces 597C C. Subsequences(dp+树状数组)
题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...
- CodeForces - 597C:Subsequences (主席树+DP)
For the given sequence with n different elements find the number of increasing subsequences with k + ...
- codeforces 597C (树状数组+DP)
题目链接:http://codeforces.com/contest/597/problem/C 思路:dp[i][j]表示长度为i,以j结尾的上升子序列,则有dp[i][j]= ∑dp[i-1][k ...
- CodeForces - 1183E Subsequences (easy version) (字符串bfs)
The only difference between the easy and the hard versions is constraints. A subsequence is a string ...
- codeforces#1183H. Subsequences(字符串dp)
题目链接: http://codeforces.com/contest/1183/problem/H 题意: 给出一个长度为$n$的字符串,得到$k$个子串,子串$s$的花费是$n-|s|$ 计算最小 ...
随机推荐
- Oracle 序列(自增ID)
-- 创建序列CREATE SEQUENCE "JPADMIN"."SEQ_JP_BAS_USER_ID" MINVALUE 1 // 最小值MAXVALUE ...
- echarts Y轴数据类型不同怎么让折线图显示差距不大
如果希望在同一grid中展示不同数据类型的折线(1000或10%),那么展现出来的折线肯定显示差距很大,那么怎么让这两条折线显示效果差不多,在之前的项目中碰到了这个问题 每条折线对应的是不同的数据组, ...
- 段错误:使用opencv打开视频流
段错误:使用opencv打开视频流时报这个错误 1 使用命令dmesg 发现是libavutil.so模块发生了错误. 如果是java端报错,可能如下: libavutil.so ... av_di ...
- (转)linux expr命令参数及用法详解
linux expr命令参数及用法详解 原文:http://blog.csdn.net/tianmohust/article/details/7628694 expr用法 expr命令一般用于整数值, ...
- nyoj 546——Divideing Jewels——————【dp、多重背包板子题】
Divideing Jewels 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 Mary and Rose own a collection of jewells. ...
- 如何给swing加上alt+x和ctrl+x快捷键
1.给菜单栏上的菜单alt+x快捷键非常简单: private JMenu helpInfo = new JMenu("帮助"); helpInfo.setMnemonic(Key ...
- /Date(1410019200000+0800)/如何转换为date对象
<script type="text/javascript">var s = '/Date(1410019200000+0800)/ '; s.replace(/Dat ...
- shell命令修改文件内容
有个 test.txt 文件内容为 hello tom,现在修改成 hello jerry,并保存到test2.txt sed 's/tom/jerry/g' test.txt >test2. ...
- Wp及Windows应用商店程序Logo生成器
在开发wp或windows应用商店程序时,需要制作不同分辨率下的logo,往往不同分辨率下的logo仅仅是图片尺寸或图片的内边距不同,为了快速生成不同分辨率下的图片,减少工作量,于是就自己动手开发了个 ...
- hdu 3642 覆盖3次以上体积
http://www.cnblogs.com/kane0526/archive/2013/03/06/2947118.html 题目大意:给你n个立方体,求相交区域大于等于三次的体积和. 这题需要前面 ...