标签:ems ted printf tar else blog eof == bsp
http://acm.hdu.edu.cn/showproblem.php?pid=5542
【题意】
【思路】
【Accepted】
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<cmath> using namespace std; typedef long long ll; const ll mod=1e9+7; const int maxn=1e3+3; ll a[maxn]; ll b[maxn]; ll dp[maxn][maxn]; int cnt; int n,m; int lowbit(int x) { return x&(-x); } ll add(int x,int y,ll d) { while(x<=n) { dp[x][y]=(dp[x][y]+d)%mod; x+=lowbit(x); } } ll sum(int x,int y) { ll res=0ll; while(x) { res=(res+dp[x][y])%mod; x-=lowbit(x); } return res; } int main() { int T; scanf("%d",&T); int cas=0; while(T--) { memset(dp,0,sizeof(dp)); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { scanf("%lld",&a[i]); } memcpy(b,a,sizeof(b)); sort(a+1,a+n+1); //cnt=unique(a+1,a+n+1)-a-1; for(int i=1;i<=n;i++) { int pos=lower_bound(a+1,a+n+1,b[i])-a; for(int j=1;j<=min(i+1,m);j++) { ll tmp; if(j==1) tmp=1ll; else tmp=sum(pos-1,j-1); add(pos,j,tmp); } } ll ans=sum(n,m); printf("Case #%d: %d\n",++cas,(int)ans); } return 0; }
【疑问】
为啥不可以去重?
【树状数组+dp】HDU 5542 The Battle of Chibi
标签:ems ted printf tar else blog eof == bsp
原文地址:http://www.cnblogs.com/itcsl/p/7241523.html