Creation August question set time Master (Timer), creationaugust

Time master

Timer. c/cpp/pas

TimerAugust masters the parallel world of different timelines in endless time periods.

New Worlds are created, and some of them are rooted in the beliefs of existing creatures.

It's the digital world of the dead soul community... As long as you have enough faith, the heart of the world will capture these beliefs and build a new world. Different worlds have different numbers and different faith values.

Unfortunately, you are selected by him. now you need to be 2 S unfortunately, you have been selected by him. now you need to answer his question within 2 seconds (it takes a long time for a Timer to take control of the time ), otherwise, it will be thrown into the cracks of time and become a static work of art forever.

Input

The number n, k, and n in the first line indicate the number of the world. k indicates the number of k-yuan Reverse Order groups.

Each row in the next n Rows has one number, indicating the belief value of each world (not exceeding the int range and not repeating)

Output

Number of outputs. (Modulo 10 ^ 9 + 7)

Data range: Hint

For 100% of data, 1 ≤ n ≤ 10 ^ 5 ≤ 1 ≤ k ≤ 10. (when k = 1 is special, the answer is 0)

For 30% of data, 1 ≤ n ≤ 10.

Sample Input

4 3

10 8 3 1

Sample Output

4

Find you with endless years

To analyze this question, the question is very simple, that is, to find the k-yuan Reverse Order Group. First, the method of binary reverse order is very simple, so to k yuan, it is actually based on the previous dollar, adding 1 yuan, in this way, the Merge Sorting Process can be called multiple times.

Additional TA code:

`//orz CA#include<cstdio>#include<cstring>#include<algorithm>#include<cstdlib>#include<cmath>#include<iostream>#define Mod 1000000007using namespace std;int f[11][100005],tf[100005],a[100005],ta[100005],k,b[100005];int hash[100005];char * cp=(char *)malloc(2000000);inline void in(int &x){ while(*cp<'0'||*cp>'9')++cp; x=0; while(*cp>='0'&&*cp<='9')x=x*10+(*cp++^'0');}inline void merge(int l,int r){ if(l==r)return; int m=l+r>>1; merge(l,m),merge(m+1,r); //printf("[%d,%d]\n",l,r); int i=l,j=m+1,o=l,s=0; for(;i<=m&&j<=r;++o) if(a[i]<a[j]){ ta[o]=a[i]; tf[o]=(f[k][i]+s)%Mod; //cout<<"Get:"<<a[i]<<" "<<s<<endl; ++i; } else{ ta[o]=a[j],tf[o]=f[k][j]; s=(s+f[k-1][a[j]])%Mod; ++j; } memcpy(ta+o,a+i,sizeof(int)*(m-i+1)); for(;i<=m;++i,++o){ tf[o]=(f[k][i]+s)%Mod; //cout<<"Get:"<<a[i]<<" "<<s<<endl; } memcpy(ta+o,a+j,sizeof(int)*(r-j+1)); memcpy(tf+o,f[k]+j,sizeof(int)*(r-j+1)); memcpy(a+l,ta+l,sizeof(int)*(r-l+1)); memcpy(f[k]+l,tf+l,sizeof(tf[0])*(r-l+1));}int main(){ freopen("timer.in","r",stdin); freopen("timer.out","w",stdout); int n,i,K; fread(cp,1,2000000,stdin); in(n),in(K); if(K==1){ puts("0"); return 0; } for(i=1;i<=n;++i){ in(b[i]); f[1][i]=1; hash[i]=b[i]; } sort(hash+1,hash+n+1); for(i=n;i;--i)b[i]=lower_bound(hash,hash+n+1,b[i])-hash; for(k=2;k<=K;++k){ memcpy(a,b,sizeof(int)*(n+1)); merge(1,n); } int ans=0; for(i=n;i;--i)ans=(ans+f[K][i])%Mod; printf("%d\n",ans);}`

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.