codeforces 597C Subsequences
2015-11-23 19:09
861 查看
C. Subsequences
For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed that the answer is not greater than 8·1018.Input
First line contain two integer values n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 10) — the length of sequence and the number of elements in increasing subsequences.
Next n lines contains one integer ai (1 ≤ ai ≤ n) each — elements of sequence. All values ai are different.
Output
Print one integer — the answer to the problem.
Sample test(s)
Input
5 2 1 2 3 5 4
Output
7
#include<cstdio> #include<vector> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; const int maxn=100005; ll c[15][maxn]; int lowbit(int x) { return x&(-x); } void update(int st,ll val,int ed,int id) { for(int i=st;i<=ed;i+=lowbit(i)) c[id][i]+=val; } ll query(int st,int id) { ll res=0; for(int i=st;i>0;i-=lowbit(i)) res+=c[id][i]; return res; } int main() { int n,k; scanf("%d%d",&n,&k); for(int i=1;i<=n;i++) { int tmp; scanf("%d",&tmp); update(tmp,1,n,0); for(int i=1;i<=k;i++) update(tmp,query(tmp-1,i-1),n,i); } printf("%I64d\n",query(n,k)); return 0; }
相关文章推荐
- Github gui使用
- UIAlertView
- UINavigationController总结
- easyUI 验证
- UIViewController的生命周期及iOS程序执行顺序
- CYC-关于UIImagePickerController
- Easyui datagrid editor为combobox时指定数据源
- 百度编辑器 多图片批量上传 顺序混乱问题 ueditor
- EasyUI----DataGrid行明细增删改操作
- reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier cellIdentifie
- Kibana User Guide [4.2] » Settings » Setting Kibana Server Properties
- [LeetCode] Range Sum Query - Mutable
- iOS-UIImage 互转 UIColor
- 二十六天( UI开始)
- iOS 【UIKit-UIPickerView】
- mrc下自定义UITableViewCell写法
- datagrid参数queryParams--easyUI
- EASYUI datagrid批量修改与提交
- Kibana User Guide [4.2] » Settings » Setting Advanced Options
- hdu5568 sequence2(dp + 高精度)