本文主要是介绍UVA12983 The Battle of Chibi,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章目录
R e s u l t Result Result
H y p e r l i n k Hyperlink Hyperlink
https://www.luogu.com.cn/problem/UVA12983
D e s c r i p t i o n Description Description
T T T组数据,每组数据给定一个长度为 n n n的序列 A A A,问 m m m元上升子序列个数,答案对 1 0 9 + 7 10^9+7 109+7取模
数据范围: n , m ≤ 1000 n,m\leq 1000 n,m≤1000
S o l u t i o n Solution Solution
我们只关心大小关系,不关心具体数值,所以先离散化
设 f i , j f_{i,j} fi,j表示长度为 i i i,以 j j j结尾的 L I S LIS LIS个数,用树状数组维护转移
拓展: n n n如果大到 1 0 5 10^5 105级别的话,如果数据纯随机构造,第一维可以只开到 n \sqrt n n,因为 L I S LIS LIS的期望长度就是 n \sqrt n n级别的
C o d e Code Code
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#define LL long long
#define N 1010
#define mod 1000000007
using namespace std;int n,m,k,a[N],b[N],T,cas;
LL f[N][N],res,C[N];
inline void A(int x,LL y){for(;x<=n;x+=x&-x)C[x]+=y,C[x]%=mod;return;}
inline LL Q(int x){LL s=0;for(;x;x-=x&-x)s+=C[x],s%=mod;return s;}
inline LL read()
{LL d=1,f=0;char c;while(c=getchar(),!isdigit(c)) if(c=='-') d=-1;f=(f<<3)+(f<<1)+c-48;while(c=getchar(),isdigit(c)) f=(f<<3)+(f<<1)+c-48;return d*f;
}
signed main()
{T=read();while(T--){n=read();k=read();for(register int i=1;i<=n;i++) b[i]=a[i]=read();sort(b+1,b+1+n);m=unique(b+1,b+1+n)-b-1;for(register int i=1;i<=n;i++) f[1][i]=1,a[i]=lower_bound(b+1,b+1+m,a[i])-b;for(register int i=2;i<=k;i++) {fill(C+1,C+1+n,0);for(register int j=1;j<=n;j++){f[i][j]=Q(a[j]-1);A(a[j],f[i-1][j]);}}res=0;for(register int i=k;i<=n;i++) res+=f[k][i],res%=mod;printf("Case #%d: %lld\n",++cas,res);}
}
这篇关于UVA12983 The Battle of Chibi的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!