【USACO】奶牛抗议 树状数组+dp
题目描述
输入
输出
• 单个整数:表示分组方案数模 1000000009 的余数
样例输入
样例输出
提示
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 typedef long long ll; 7 const int mod=1000000009,N=100005; 8 int gi(){ 9 int str=0,f=1;char ch=getchar(); 10 while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();} 11 while(ch>='0' && ch<='9')str=str*10+ch-48,ch=getchar(); 12 return str*f; 13 } 14 int a[N],id[N],n;ll Tree[N*4],sum[N],b[N],f[N]; 15 int pf(ll x) 16 { 17 int l=1,r=n,mid; 18 while(l<=r) 19 { 20 mid=(l+r)>>1; 21 if(b[mid]==x)return mid; 22 if(x>b[mid])l=mid+1; 23 else r=mid-1; 24 } 25 return 0; 26 } 27 void add(int sta,ll x){for(int i=sta;i<=n;i+=(i&(-i)))Tree[i]+=x,Tree[i]%=mod;} 28 ll getsum(int sta) 29 { 30 ll sum=0; 31 for(int i=sta;i>=1;i-=(i&(-i)))sum+=Tree[i],sum%=mod; 32 return sum; 33 } 34 int main() 35 { 36 n=gi(); 37 for(int i=1;i<=n;i++)a[i]=gi(),sum[i]=sum[i-1]+a[i],b[i]=sum[i]; 38 sort(b+1,b+n+1); 39 for(int i=1;i<=n;i++) 40 { 41 id[i]=pf(sum[i]); 42 } 43 for(int i=1;i<=n;i++) 44 { 45 f[i]=getsum(id[i]); 46 if(sum[i]>=0)f[i]++; 47 f[i]%=mod; 48 add(id[i],f[i]); 49 } 50 printf("%lld",f[n]%mod); 51 return 0; 52 }
转载于:https://www.cnblogs.com/Yuzao/p/7053785.html
【USACO】奶牛抗议 树状数组+dp相关推荐
- HDU-5542-The Battle of Chibi【树状数组+dp】
HDU-5542-The Battle of Chibi[树状数组+dp] Time Limit: 6000/4000 MS (Java/Others) Memory Limit: 65535/655 ...
- HDU - 5542 The Battle of Chibi(树状数组+DP)
UVA - 12983 The Battle of Chibi(树状数组+DP) HDU - 5542 The Battle of Chibi(树状数组+DP) #include<cstdio& ...
- CodeForces 314C 树状数组 + dp
//CodeForces 314C //分析:相当于求给定序列的不降子序列的个数,从一个空序列开始将得到的不降子序列不断的延长是典型的做法,则dp[i]表示以第 i 个元素结尾的序列 //思路:O(n ...
- bzoj 2131: 免费的馅饼(树状数组+DP)
2131: 免费的馅饼 Time Limit: 10 Sec Memory Limit: 259 MB Submit: 408 Solved: 245 [Submit][Status][Discu ...
- hdu 6447YJJ's Salesman 离散化+树状数组+DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6447 因为图中点的坐标值过大,达到1e9.然而只有1e5个点.所以先将其离散化.并按照<x.y& ...
- CF985E Pencils and Boxes(树状数组+dp)
树状数组优化dp问题 #include<bits/stdc++.h> using namespace std; const int N=5e5+10; int n,k,d; int b[N ...
- 2019计蒜之道复赛A:外教Michale变身大熊猫【树状数组+dp】
题目: 题目在这里~~~ 分析: 按照题意,只需要找到最长上升子序列的数量和每个数对最长上升子序列的贡献次数即可,可以二分找到经过每个数的最长上升子序列的长度,但这样不好统计数量:考虑dp,定义dp[ ...
- M元上升子序列【树状数组+dp】
多元组-牛客网 题解 ac代码 #include<iostream> #include<cstring> #include<algorithm> #include& ...
- P3287-[SCOI2014]方伯伯的玉米田【二维树状数组,dp】
正题 题目链接:https://www.luogu.com.cn/problem/P3287 题目大意 nnn个玉米高度不同,可以选择kkk个区间拔高111个高度,求最长不降子序列长度. 解题思路 显 ...
最新文章
- 《利用python进行数据分析》读书笔记--第十章 时间序列(二)
- Call调用webservice接口,使用命名空间和不使用命名空间的区别
- postgresql 比较两个时间差大于 N个小时
- C#GRPC 服务端与客户端通信,故障排除记录
- 数组(array)(小谈)
- 关于智能推荐的几点思考
- laravel5.4中验证与错误提示设置
- 20200612每日一句
- c 连接oracle otl,C++类库:OTL通用的数据库连接类库
- 电脑芯片级维修点常用工具一览
- scala linearization
- Axure RP 9 授权码
- MFC 按钮控件添加图片
- 什么是数据库分组查询(详解)
- 分布式数据库CAP理论
- SAP中重复制造生产计划编制——生产版本
- Latex中的实心原点
- 那些不起眼的流量大户在做什么?(转载)
- Fine-grained Detection —— DCL
- 智能照明控制系统java代码_基于Android的智能照明控制系统设计毕业设计.pdf