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|$ 计算最小 ...
随机推荐
- DNS服务器设置
1,域名解析:ip能够访问,但是域名不能访问. 2,配置好网络之后,切换到命令行模式,配置好的网络便不能用了. 具体方法: 打开vim /etc/sysconfig/network-scripts/i ...
- oracle dblink简介
database link概述 database link是定义一个数据库到另一个数据库的路径的对象,database link允许你查询远程表及执行远程程序.在任何分布式环境里,database都是 ...
- 【ubuntu】更换下载源
ubuntu,我们在使用apt新装软件的时候,会使用官方的网站去下载软件,但是会因为国内的转接点太多,而导致下载的速度非常慢 ,我们可以通过换成一些中间的节点来进行下载,比如阿里源,中科大源,清华源等 ...
- Vue1.0基础学习笔记整理
最近一直在使用Vue.js开发项目,现将在学习过程中遇到的一些学习小细节总结如下: 1.只处理单次插值,今后的数据变化就不会再引起插值更新了 <span>This will never c ...
- c#.net常见字符串处理方法
1.字符串比较 字符串.ComparTo(目标字符串) "a".ComparTo("b"); 2.查找子串 字符串.IndexOf(子串,查找其实位置) ; 字 ...
- TensorFlow入门:安装常用的依赖模块
TensorFlow运行中常用到一些Python第三方模块: numpy 存储和处理大型矩阵的科学计算包 maplotlib 最著名的绘图库 jupyter scikit-image 图像预处理 li ...
- jq实现发送验证码倒计时60s
setInterval() :按照指定的周期(以毫秒计)来调用函数或计算表达式.方法会不停地调用函数,直到 clearInterval() 被调用或窗口被关闭. setTimeout() :在指定的毫 ...
- Web前端面试指导(九):盒子模型你是怎么理解的?
问题分析 这道题问得比较宽泛,一定要找准切入点,如果切入点找不准,很容易乱答,甚至答偏,所以找准切入点是非常的重要的. 解答思路 1)盒子模型有两种,W3C和IE盒子模型 (1)W3C定义的盒子模型包 ...
- Highcharts error #14: www.highcharts.com/errors/14
错误原因:数据类型错误,需要的是Number类型,传入的却是String 以为为官网说明: Highcharts Error #14 String value sent to series.data, ...
- linux里终端安转视频播放器的操作及显示
[enilu@enilu ~]$ mplayerbash: mplayer: command not found[enilu@enilu ~]$ yum list | grep mplayer^C^C ...