您的位置:首页 > 其它

时间之主 解题报告

2015-07-06 20:12 253 查看
时间之主

Timer.c/cpp/pas

TimerAugust掌握着无尽时间里不同时间轴的平行世界.每一个瞬间都会有

新的世界被创造出来,其中一些世界被创造出来的根源就是已有生灵的信仰.无论

是尸魂界幻想乡数码世界…只要有足够的信仰,世界之心就会抓取这些信仰并用

来构建成新的世界.不同世界有不同编号和不同信仰值.

现在 TimerAugust想知道对世界 1..n,有信仰值 a

1

..a

n

,其中那些

i

[code]#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
using namespace std;
#define Mod 1000000007
#include<algorithm>
void in(int &x){
    char c=getchar();
    bool flag=0;
    for(;c<'0'||c>'9';c=getchar())
        if(c=='-')
            flag=1;
    x=0;
    for(;c>='0'&&c<='9';c=getchar())x=x*10+c-'0';
    if(flag)x=-x;
}
int f[15][100005];
int hash[100005],a[100005],htot;
int query(int k,int x){
    int ans=0;
    for(;x;x-=x&-x)ans=(ans+f[k][x])%Mod;
    return ans;
}
int update(int k,int x,int A){
    for(;x<htot;x+=x&-x)f[k][x]=(f[k][x]+A)%Mod;
}
int main(){
    freopen("timer.in","r",stdin);
    freopen("timer.out","w",stdout);
    int n,k,i,j;
    in(n),in(k);
    if(k==1){
        puts("0");
        return 0;
    }
    for(i=1;i<=n;++i)in(a[i]),hash[i]=a[i];
    sort(hash+1,hash+n+1);
    htot=unique(hash+1,hash+n+1)-hash;
    for(i=n;i;--i)a[i]=lower_bound(hash+1,hash+htot,a[i])-hash;
    for(i=n;i;--i){
        update(1,a[i],1);
        for(j=2;j<=k;++j)update(j,a[i],a[i]>1?query(j-1,a[i]-1):0);
    }
    printf("%d\n",query(k,htot-1));
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: