日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hdu 4991(树状数组优化dp)

發(fā)布時間:2025/3/16 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hdu 4991(树状数组优化dp) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Ordered Subsequence

Time Limit: 4000/2000 MS (Java/Others)????Memory Limit: 32768/32768 K (Java/Others)

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.
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
Output For each case, output answer % 123456789.
Sample Input 3 2 1 1 2 7 3 1 7 3 5 9 4 8
Sample Output 2 12 解題思路:這道題和hdu 5542完全一樣,長度為m的遞增子序列的個數(shù),樹狀數(shù)組+dp。 #include<iostream> #include<cstdio> #include<cstring> #include<set> #include<map> using namespace std;const int maxn = 10005; const int mod = 123456789; int n,m; int tree[105][maxn],a[maxn]; set<int> Set; map<int,int> Map;int lowbit(int x) {return x & -x; }void update(int i,int x,int c) {while(x <= n){tree[i][x] = (tree[i][x] + c) % mod;x += lowbit(x);} }int getsum(int i,int x) {int sum = 0;while(x > 0){sum = (sum + tree[i][x]) % mod;x -= lowbit(x);}return sum; }int main() {while(scanf("%d%d",&n,&m)!=EOF){Map.clear();Set.clear();memset(tree,0,sizeof(tree));for(int i = 1; i <= n; i++){scanf("%d",&a[i]);Set.insert(a[i]);}int cnt = 0;for(set<int>::iterator it = Set.begin(); it != Set.end(); it++)Map[*it] = ++cnt;for(int i = 1; i <= n; i++)for(int j = 1; j <= m; j++){int tmp = 0;if(j == 1) tmp = 1;else tmp = (tmp + getsum(j-1,Map[a[i]]-1)) % mod;update(j,Map[a[i]],tmp);}printf("%d\n",getsum(m,cnt));}return 0; }

總結(jié)

以上是生活随笔為你收集整理的hdu 4991(树状数组优化dp)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。