hdu 4991 Ordered Subsequence(Bestcoder Round #8 1003)
来源:互联网 发布:美工需要会什么软件 编辑:程序博客网 时间:2024/05/22 17:08
Ordered Subsequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 214 Accepted Submission(s): 109
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
数据的离散化+树状数组
第一次了解离散化点击打开链接
//562ms#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>using namespace std;const int maxn=10000+100;const int mod=123456789;int a[maxn+10],b[maxn+10];int dp[110][maxn+10];int low(int k){ return (k&-k);}int getsum(int k,int u){ int ans=0; while(k>0) { ans=(ans+dp[u][k])%mod; k-=low(k); } return ans;}void update(int u,int k,int v){ while(k<maxn) { dp[u][k]=(dp[u][k]+v)%mod; k+=low(k); }}int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); b[i]=a[i]; } if(n<m) { printf("0\n"); continue; } sort(b+1,b+n+1);//数据的离散化 int size=unique(b+1,b+n+1)-b-1;//离散后的长度,去重 for(int i=1;i<=n;i++) a[i]=lower_bound(b+1,b+n+1,a[i])-b;//离散后的值 update(1,a[1],1); // printf("jsd\n"); for(int i=2;i<=n;i++) { for(int j=m;j>=2;j--)//枚举前面所有可能的长度 { int sum=getsum(a[i]-1,j-1); update(j,a[i],sum); } update(1,a[i],1); } int ans=getsum(size,m); printf("%d\n",ans); } return 0;}
0 0
- hdu 4991 Ordered Subsequence(Bestcoder Round #8 1003)
- HDU-4991-Ordered Subsequence
- hdu 4991 Ordered Subsequence
- HDU 4991 Ordered Subsequence
- HDU 4991 / BC 8C Ordered Subsequence
- hdu 4991 Ordered Subsequence(DP优化—树状数组)
- HDU 4991 Ordered Subsequence(dp+树状数组)
- hdu 4991 Ordered Subsequence(树状数组+DP)
- 【树状数组】 HDU 4991 Ordered Subsequence
- hdu 4991 Ordered Subsequence(dp+树状数组)
- HDU 4991 Ordered Subsequence -- DP+树状数组
- 【HDU】4991 Ordered Subsequence 线段树&树状数组
- hdu 4991 Ordered Subsequence(树状数组优化DP)
- HDU-4991-Ordered Subsequence【树状数组】【动态规划】【好题】
- HDU 4991 Ordered Subsequence DP(套路,BIT优化)
- hdu 4990 Reading comprehension(BestCoder Round #8 1002)
- [BestCoder Round #3] hdu 4908 BestCoder Sequence (计数)
- hdu 5592 BestCoder Round #65 1003
- IT职业之路
- Qt 常用类 (7)QPixmap/8--QIcon
- 乐惠通手机十元包月全国任打--项目详解
- C#.NET验证码智能识别学习笔记---06 解决java jre问题:JTessBoxEditor.jar打开的时报找不到或无法加载主类 com.sun.tools.javac.Main错误
- Beautiful numbers(记搜经典)
- hdu 4991 Ordered Subsequence(Bestcoder Round #8 1003)
- LA 3942 Remember the Word
- Qt 常用类 (9)—— QWidget
- Erp
- fedora18-64 bit安装STM32 GCC编译环境(1)
- hdu2871 Memory Control 线段树区间合并+STL删除插入
- 乐惠通手机十元包月全国任打--制度详解
- coco2d-x单例的实现
- php字符串操作