From ef090cad703ee582a24c0f06e435e5c4d3896b73 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Wed, 27 Apr 2016 10:35:10 +0800 Subject: [PATCH] From http://www.cnblogs.com/d-e-v-i-l/p/5436931.html --- SDUSTOJ/1801.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 SDUSTOJ/1801.cpp diff --git a/SDUSTOJ/1801.cpp b/SDUSTOJ/1801.cpp new file mode 100644 index 0000000..ecfca56 --- /dev/null +++ b/SDUSTOJ/1801.cpp @@ -0,0 +1,62 @@ +/* *********************************************** +Author :devil +Created Time :2016/4/26 22:18:57 +************************************************ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +const int N=110; +const int mod=1e9+9; +LL dp[N][N],dp2[N][N]; +int a[N],b[N]; +int main() +{ + //freopen("in.txt","r",stdin); + int t,n,m; + scanf("%d",&t); + while(t--) + { + scanf("%d%d",&n,&m); + for(int i=1; i<=n; i++) + scanf("%d",&a[i]); + memset(dp,0,sizeof(dp)); + memset(dp2,0,sizeof(dp2)); + memset(b,-1,sizeof(b)); + b[a[1]]=dp[a[1]][1]=1; + for(int i=2;i<=n;i++) + { + dp[a[i]][1]=1; + int mi=min(i,m); + for(int k=2;k<=mi;k++) + { + for(int j=1;j=mod) dp[a[i]][k]-=mod; + } + if(b[a[i]]!=-1) + { + dp[a[i]][k]-=dp2[a[i]][k]; + if(dp[a[i]][k]<0) dp[a[i]][k]+=mod; + } + dp2[a[i]][k]=dp[a[i]][k]; + } + b[a[i]]=i; + } + LL ans=0; + for(int i=1;i<=n;i++) + ans=(ans+dp[i][m])%mod; + printf("%lld\n",ans); + } + return 0; +}