时间之主 解题报告
2015-07-06 20:12
253 查看
时间之主
Timer.c/cpp/pas
TimerAugust掌握着无尽时间里不同时间轴的平行世界.每一个瞬间都会有
新的世界被创造出来,其中一些世界被创造出来的根源就是已有生灵的信仰.无论
是尸魂界幻想乡数码世界…只要有足够的信仰,世界之心就会抓取这些信仰并用
来构建成新的世界.不同世界有不同编号和不同信仰值.
现在 TimerAugust想知道对世界 1..n,有信仰值 a
1
..a
n
,其中那些
i
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)); }
相关文章推荐
- senaphore
- Android入门(13)——GridView使用汇总
- 大约apache 2.4.X虚拟主机配置问题的版本号后,
- 抽象工厂模式(Abstract Factory)
- 第0周-JAVA云课堂学习日志
- 从oracle中导出数据表 —— 使用命令行
- 如何将Mac OS X10.9下的Python2.7升级到最新的Python3.3
- AdaBoost中利用Haar特征进行人脸识别算法分析与总结1——Haar特征与积分图
- 结构体浅谈
- java问题查找------从源头查找
- HDU1300DP
- 安卓平台搭建
- malloc/free与new/delete的区别
- oracle实现分页-- 红黑
- 随笔
- 黑马程序员——java基础---集合(第16天)
- begingthread afxbeginthread createthread
- 塑造职业品牌培训-记录
- 黑马程序员 ————第一天
- selenium2(WebDriver) API