HDU 4991 Rabbit Kingdom(二维树状数组)
来源:互联网 发布:centos7 php配置文件 编辑:程序博客网 时间:2024/06/04 20:09
Problem Description
A numeric sequence of ai is ordered if a1<a2<……<aN. Let the subsequence of the given numeric sequence (a1, a2,……, aN) be any sequence (ai1, ai2,……, aiK), where 1<=i1<i2 <……<iK<=N. For example, sequence (1, 7, 3, 5, 9, 4, 8) has ordered subsequences, eg. (1, 7), (3, 4, 8) and many others.
Your program, when given the numeric sequence, must find the number of its ordered subsequence with exact m numbers.
Your program, when given the numeric sequence, must find the number of its ordered subsequence with exact m numbers.
Input
Multi test cases. Each case contain two lines. The first line contains two integers n and m, n is the length of the sequence and m represent the size of the subsequence you need to find. The second line contains the elements of sequence - n integers in the range from 0 to 987654321 each.
Process to the end of file.
[Technical Specification]
1<=n<=10000
1<=m<=100
Process to the end of file.
[Technical Specification]
1<=n<=10000
1<=m<=100
Output
For each case, output answer % 123456789.
Sample Input
3 21 1 27 31 7 3 5 9 4 8
Sample Output
212
其实题意很好理解。设dp[i][j]表示以第i个结尾并且有j个的数量。
则dp[i][j]=sum(dp[k][j-1]);接下来就是树状数组维护了。
#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<string>#include<iostream>#include<queue>#include<cmath>#include<map>#include<stack>#include<bitset>using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )typedef long long LL;typedef pair<int,int>pil;const int MOD = 123456789;const int maxn=10000+5;int n,m,len;//dp[i][j]=sum(dp[k][j-1])(k<i);LL c[105][maxn];//i第几层的树状数组LL a[maxn],b[maxn];int lowbit(int x){ return x&(-x);}void update(int x,LL val,int f){ while(x<=len) { c[f][x]=(c[f][x]+val)%MOD; x+=lowbit(x); }}LL query(int x,int f){ LL s=0; while(x>0) { s=(s+c[f][x])%MOD; x-=lowbit(x); } return s;}int main(){ while(~scanf("%d%d",&n,&m)) { CLEAR(c,0); REP(i,n) { scanf("%I64d",&a[i]); b[i]=a[i]; } sort(b,b+n); len=unique(b,b+n)-b; REP(i,n) { int pos=lower_bound(b,b+len,a[i])-b+1; update(pos,1,1); REPF(j,2,m) { LL num=query(pos-1,j-1); update(pos,num,j); } } printf("%I64d\n",query(len,m)); } return 0;}
0 0
- HDU 4991 Rabbit Kingdom(二维树状数组)
- hdu 4777 Rabbit Kingdom(树状数组)
- HDU 4777 Rabbit Kingdom(树状数组)
- hdu 4777 Rabbit Kingdom(树状数组)
- hdu 4777 Rabbit Kingdom (离线树状数组)
- HDU 4777 - Rabbit Kingdom (树状数组 区间互素数)
- HDU 4777 Rabbit Kingdom(树状数组+离线预处理)
- hdu 4777 Rabbit Kingdom(离线+树状数组)
- hdu 4777 Rabbit Kingdom 离线树状数组
- [HDU 4777 Rabbit Kingdom] 离线+树状数组
- hdu 4777 Rabbit Kingdom(树状数组)
- hdu 4777 Rabbit Kingdom 离线+树状数组
- Hdu 4777 Rabbit Kingdom 树状数组
- HDU 4777 Rabbit Kingdom [离线+树状数组]
- HDU 4777 Rabbit Kingdom【树状数组】
- hdu 4777 Rabbit Kingdom 树状数组
- HDU 4777 Rabbit Kingdom(树状数组 离线)
- hdu-4777Rabbit Kingdom 树状数组
- TNS-01185: Registration attempted from a remote node
- [GEngine]相机角色中间物体透明(BetweenTransparent)
- RAC TNS-1184和1185错误解决
- 使用filter配合装饰器模式实现对请求参数加密
- Connected to an idle instance
- HDU 4991 Rabbit Kingdom(二维树状数组)
- Unity3d的2D骨骼动画插件Puppet2D的 基础训练1
- Computer Identifier
- 关于myeclipse或者eclipse中导出jar包
- 软件滤波,硬件滤波
- Unity3d的2D骨骼动画插件Puppet2D的 基础训练2
- LeetCode 之 Remove Nth Node From End of List
- air max femme pas cher he eventually transferred to the School of Journalism Department radio and te
- LeetCode 之 preorder traversal of binary tree