codeforce 597C-Subsequences(dp+树状数组)

题目和南阳那道题一样链接http://www.cnblogs.com/zzuli2sjy/p/4943774.html
代码:
1 #include<stdio.h>
2 #include<algorithm>
3 #include<string.h>
4 #include<stdlib.h>
5 #include<iostream>
6 #include<map>
7 typedef long long ll;
8 const ll N=1e5+5;
9 ll dp[20][N];
10 ll a[N];
11 ll bit[N];
12 int found(int n,int m,ll k);
13 ll sum(int i);
14 void add(int i,ll x,int t);
15 using namespace std;
16 int main(void)
17 {
18 ll i,j,k,p,q;
19 while(scanf("%I64d %I64d",&k,&p)!=EOF)
20 {
21 memset(dp,0,sizeof(dp));
22 memset(bit,0,sizeof(bit));
23 for(i=0; i<k; i++)
24 {
25 scanf("%I64d",&a[i]);
26 }int cnt=k;
27 for(i=0; i<k; i++)
28 {
29 dp[1][i]=1;
30 }
31 for(i=2; i<=p+1; i++)
32 {
33 memset(bit,0,sizeof(bit));
34 for(j=i-2; j<k; j++)
35 {
36 dp[i][j]=sum(a[j]-1);
37 add(a[j],dp[i-1][j],cnt);
38 }
39
40 }
41 ll sum=0;
42 for(i=0; i<k; i++)
43 {
44 sum+=dp[p+1][i];
45
46 }
47 printf("%I64d\n",sum);
48 }
49 return 0;
50 }
51 ll sum(int i)
52 {
53 ll s=0;
54 while(i>0)
55 {
56 s+=bit[i];
57 i-=(i&-i);
58 }
59 return s;
60 }
61
62 void add(int i,ll x,int t)
63 {
64 while(i<=t)
65 {
66 bit[i]+=x;
67 i+=(i&-i);
68 }
69 }
codeforce 597C-Subsequences(dp+树状数组)的更多相关文章
- codeforces 597C C. Subsequences(dp+树状数组)
题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...
- HDU 2227 Find the nondecreasing subsequences (DP+树状数组+离散化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2227 Find the nondecreasing subsequences ...
- CodeForces - 597C Subsequences (树状数组+动态规划)
For the given sequence with n different elements find the number of increasing subsequences with k + ...
- 树形DP+树状数组 HDU 5877 Weak Pair
//树形DP+树状数组 HDU 5877 Weak Pair // 思路:用树状数组每次加k/a[i],每个节点ans+=Sum(a[i]) 表示每次加大于等于a[i]的值 // 这道题要离散化 #i ...
- bzoj 1264 [AHOI2006]基因匹配Match(DP+树状数组)
1264: [AHOI2006]基因匹配Match Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 793 Solved: 503[Submit][S ...
- 【bzoj2274】[Usaco2011 Feb]Generic Cow Protests dp+树状数组
题目描述 Farmer John's N (1 <= N <= 100,000) cows are lined up in a row andnumbered 1..N. The cows ...
- 奶牛抗议 DP 树状数组
奶牛抗议 DP 树状数组 USACO的题太猛了 容易想到\(DP\),设\(f[i]\)表示为在第\(i\)位时方案数,转移方程: \[ f[i]=\sum f[j]\;(j< i,sum[i] ...
- CodeForces - 597C Subsequences 【DP + 树状数组】
题目链接 http://codeforces.com/problemset/problem/597/C 题意 给出一个n 一个 k 求 n 个数中 长度为k的上升子序列 有多少个 思路 刚开始就是想用 ...
- CodeForces - 314C Sereja and Subsequences (树状数组+dp)
Sereja has a sequence that consists of n positive integers, a1, a2, ..., an. First Sereja took a pie ...
- HDU2227Find the nondecreasing subsequences(树状数组+DP)
题目大意就是说帮你给出一个序列a,让你求出它的非递减序列有多少个. 设dp[i]表示以a[i]结尾的非递减子序列的个数,由题意我们可以写出状态转移方程: dp[i] = sum{dp[j] | 1&l ...
随机推荐
- python飞机大战
'''新手刚学python,仿着老师敲的代码.1.敌方飞机只能左右徘徊(不会往下跑)并且不会发射子弹.2.正在研究怎么写计分.3.也参考了不少大佬的代码,但也仅仅只是参考了.加油!''' import ...
- A Child's History of England.8
CHAPTER 3 ENGLAND UNDER THE GOOD SAXON, ALFRED Alfred [born in 849 CE, 唐: 618年-907年] the Great was a ...
- Shell学习(六)——条件判断总结
Shell学习(六)--条件判断总结 [1]https://www.cnblogs.com/zhw-626/p/8528001.html [2]https://www.cnblogs.com/yizh ...
- java生成cron表达式
bean类: package com.cst.klocwork.service.cron; public class TaskScheduleModel { /** * 所选作业类型: * 1 -&g ...
- Java Spring 自定义事件监听
ApplicationContext 事件 定义一个context的起动监听事件 import org.springframework.context.ApplicationListener; imp ...
- InnoDB学习(三)之BinLog
BinLog又称为二进制日志,是MySQL服务层的数据日志,MySQL所有的存储引擎都支持BinLog.BinLog记录了MySQL中的数据更新和可能导致数据更新的事件,可以用于主从复制或数据恢复.本 ...
- Python——连接数据库操作
一.数据库基础用法 要先配置环境变量,然后cmd安装:pip install pymysql 1.连接MySQL,并创建wzg库 #引入decimal模块 import pymysql #连接数据库 ...
- ctypes与numpy.ctypeslib的使用
numpy ctypeslib 与 ctypes接口使用说明 作者:elfin 目录 一.numpy.ctypeslib使用说明 1.1 准备好一个C++计算文件 1.2 ctypeslib主要的五个 ...
- 【简】题解 AWSL090429 【价值】
先考虑当要选的物品一定时 显然有个贪心 wi越小的要越先选 所以先按wi从小到大拍序 因为发现正着递推要记录的状态很多 并且wi的贡献与后面选了几个物品有关 考虑正难则反 倒着递推 提前计算wi的贡献 ...
- Service Worker的应用
Service Worker的应用 Service worker本质上充当Web应用程序.浏览器与网络(可用时)之间的代理服务器,这个API旨在创建有效的离线体验,它会拦截网络请求并根据网络是否可用来 ...