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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[HDOJ5542]The Battle of Chibi(DP,树状数组)

發(fā)布時間:2023/12/20 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [HDOJ5542]The Battle of Chibi(DP,树状数组) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=5542

題意:n個數(shù)中找m個數(shù),使得從左到右讀是上升的子序列。問一共有多少種。

dp(i,j)表示取到第i個位置,長為j并且最后一個數(shù)為a(i)的方案總數(shù)。

更新就比較容易了,dp(i,j)=∑(k=1->j-1)dp(i-1,k),初始化dp(i,1)=1。

1 #include <bits/stdc++.h> 2 using namespace std; 3 #define lowbit(x) x & (-x) 4 5 const int mod = int(1e9+7); 6 const int maxn = 1010; 7 int dp[maxn][maxn]; 8 int a[maxn], h[maxn]; 9 int n, m, hcnt; 10 11 int sum(int i, int x) { 12 int ret = 0; 13 while(x) { 14 ret = (ret + dp[i][x]) % mod; 15 x -= lowbit(x); 16 } 17 return ret; 18 } 19 20 void update(int i, int x, int k) { 21 while(x <= n) { 22 dp[i][x] = (dp[i][x] + k) % mod; 23 x += lowbit(x); 24 } 25 } 26 27 int getid(int x) { 28 return lower_bound(h, h+hcnt, x) - h; 29 } 30 31 int main() { 32 //freopen("in", "r", stdin); 33 int T, _ = 1; 34 scanf("%d", &T); 35 while(T--) { 36 printf("Case #%d: ", _++); 37 scanf("%d %d", &n, &m); 38 for(int i = 1; i <= n; i++) { 39 scanf("%d", &a[i]); 40 h[i-1] = a[i]; 41 } 42 sort(h, h+n); hcnt = unique(h, h+n) - h; 43 for(int i = 1; i <= n; i++) a[i] = getid(a[i]) + 1; 44 memset(dp, 0, sizeof(dp)); 45 for(int i = 1; i <= n; i++) { 46 for(int j = 1; j <= m; j++) { 47 if(j == 1) { 48 update(j, a[i], 1); 49 continue; 50 } 51 int tmp = sum(j-1, a[i]-1); 52 update(j, a[i], tmp); 53 } 54 } 55 printf("%d\n", sum(m, n)); 56 } 57 return 0; 58 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/kirai/p/5955780.html

總結(jié)

以上是生活随笔為你收集整理的[HDOJ5542]The Battle of Chibi(DP,树状数组)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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