100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > HDU - 5542 The Battle of Chibi(树状数组+DP)

HDU - 5542 The Battle of Chibi(树状数组+DP)

时间:2021-03-15 20:54:57

相关推荐

HDU - 5542 The Battle of Chibi(树状数组+DP)

UVA - 12983 The Battle of Chibi(树状数组+DP)

HDU - 5542 The Battle of Chibi(树状数组+DP)

#include<cstdio>#include<cstring>#include<algorithm>#include<vector>using namespace std;const int N = 1010, MOD = 1e9 + 7;int n,m,a[N],tr[N],f[N][N];void add(int x,int v){for(int i=x;i<=n;i+=(i&-i))tr[i]=(tr[i]+v)%MOD;}int sum(int x){int res=0;for(int i=x;i>0;i-=(i&-i))res=(res+tr[i])%MOD;return res;}int main(){int T;scanf("%d",&T);for(int C=1;C<=T;C++){vector<int> nums;scanf("%d%d",&n,&m);for(int i=1;i<=n;i++){scanf("%d",&a[i]);nums.push_back(a[i]);}sort(nums.begin(),nums.end());nums.erase(unique(nums.begin(),nums.end()),nums.end());for(int i=1;i<=n;i++)a[i]=lower_bound(nums.begin(),nums.end(),a[i])-nums.begin()+1;for(int i=1;i<=n;i++) f[i][1]=1;for(int j=2;j<=m;j++){for(int i=1;i<=n;i++) tr[i]=0;for(int i=1;i<=n;i++){f[i][j]=sum(a[i]-1);add(a[i],f[i][j-1]);}}int res=0;for(int i=1;i<=n;i++) res=(res+f[i][m])%MOD;printf("Case #%d: %d\n",C,res);}return 0;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。