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|$ 计算最小 ...
随机推荐
- Ubuntu电源键软关机设置
对于不连接显示器的Ubuntu设备,通过直接拔电源或者长按电源键是普遍的关机方法,但这种方法长期势必会对设备造成损坏. 下面设置电源键软关机(短摁电源按钮关机)的方法可以解决此问题.(默认摁电源键会弹 ...
- VUE项目引入微信jssdk
npm i -S weixin-js-sdkimport wx from 'weixin-js-sdk'
- Oracle RAC集群搭建(三)--挂载磁盘
一,磁盘配置 查看由上回配置的共享磁盘,一共三块-----以下所有内容均两台物理机都需要操作 查看磁盘id [root@rac2 ~]# /usr/lib/udev/scsi_id -g -u /de ...
- C++11并发编程:async,future,packaged_task,promise
一:async std::async:用于创建异步任务,可以代替创建线程,函数原型:async(std::launch::async | std::launch::deferred, f, args. ...
- ubuntu安装卸载软件
sudo apt-get remove nagios3 #卸载软件 sudo apt-get autoremove #卸载依附软件包 rpm格式 安装:rpm -ivh *** 查看:rpm -q * ...
- nyoj 546——Divideing Jewels——————【dp、多重背包板子题】
Divideing Jewels 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 Mary and Rose own a collection of jewells. ...
- github不支持tlsv1.1后, 出现SSL connect error
过完年回来, github不安分了, 发了博文说不支持TLSv1/TLSv1.1: Weak cryptographic standards removed, 没看到这篇博文之前, 还以为是代理问题, ...
- 使用mermain用Markdown的语法画流程图和UML图
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:使用mermain用Markdown的语法画流程图和UML图.
- linq(查询)
1.改变数据库某一字段的属性 db.tableName.ToList().ForEach(x => x.State = false); 2.排序 db.tableName..toList().O ...
- 1229:密码截获----java
题目描述 Catcher是MCA国的情报员,他工作时发现敌国会用一些对称的密码 进行通信,比如像这些ABBA,ABA,A,123321,但是他们有时会在开始或结束时加入一些无关的字符以防止别国破解.比 ...