4277: Sequence

Time Limit(Common/Java):2000MS/6000MS     Memory Limit:65536KByte
Total Submit:
39
          
Accepted:11

Description

YXH is very fond of the sequence. One day he found a very interesting sequence.
At time T, a sequence A is
A(1),A(2),...,A(n)
After one second (at time T + 1), the sequence will become
A(1),A(2)+2A(1),A(3)+2A(2)+3A(1),…,A(n)+2A(n-1)+...+nA(1)
YXH wants to know the sequence at time K. Can you solve this problem?

Input

There are multiple test cases.
For each case, the first line contains a number N indicating the length of the sequence. The second line contains N numbers indicating the sequence in time 0. The third line contains a number K as description above.

1 <= N <= 300, 1 <= K <= 1,000,000,000
The value of each number in the sequence will not exceed 300.

Output

For each case, print the sequence at time K in one line. Since the answer could be very large, you should output the answer module 1,000,000,007

Sample Input

3
1 2 3
2

Sample Output

1 6 21

Source

2012年武汉大学第六届E鸣杯程序设计竞赛

看似矩阵快速幂,但是这个矩阵是300*300的矩阵,很容易就爆炸了,因为矩阵乘法是n^3的,再做快速幂是logk

这个矩阵的构造应该不算是很难吧,就是填1到n,然后斜线上的值是一样的

矩阵快速幂代码

  1. #include<stdio.h>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. const int N=,MD=1e9+,INF=0x3f3f3f3f;
  5. const double eps=1e-,e=exp(),PI=acos(-.);
  6. typedef long long ll;
  7. int G;
  8. struct MX
  9. {
  10. int v[N][N];
  11. void O()
  12. {
  13. memset(v,,sizeof v);
  14. }
  15. void E()
  16. {
  17. memset(v,,sizeof v);
  18. for(int i=; i<G; i++)
  19. for(int j=i;j<G;j++)v[i][j]=j-i+;
  20. }
  21. void P()
  22. {
  23. for(int i=; i<G; i++)
  24. for(int j=; j<G; j++)printf(j==G-?"%d\n":"%d ",v[i][j]);
  25. }
  26. MX operator+(const MX &b) const
  27. {
  28. MX c;
  29. c.O();
  30. for(int i=; i<G; i++)
  31. for(int j=; j<G; j++)c.v[i][j]=v[i][j]+b.v[i][j];
  32. return c;
  33. }
  34. MX operator*(const MX &b)const
  35. {
  36. MX c;
  37. c.O();
  38. for(int k=; k<G; k++)
  39. for(int i=; i<G; i++)
  40. if(v[i][k])for(int j=; j<G; j++)c.v[i][j]=(c.v[i][j]+1LL*v[i][k]*b.v[k][j]%MD)%MD;
  41. return c;
  42. }
  43. MX operator^(int p)const
  44. {
  45. MX y,x;
  46. y.E(),memcpy(x.v,v,sizeof(v));
  47. for(; p; x=x*x,p>>=)if(p&)y=y*x;
  48. return y;
  49. }
  50. } a,ans;
  51. int main()
  52. {
  53. //ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
  54. int n,k;
  55. while(~scanf("%d",&n))
  56. {
  57. G=n;
  58. a.O();
  59. for(int i=; i<n; i++)scanf("%d",&a.v[][i]);
  60. scanf("%d",&k);
  61. ans.E();
  62. ans=ans^(k-);
  63. ans=a*ans;
  64. for(int i=; i<n; i++)printf(i==G-?"%d\n":"%d ",ans.v[][i]);
  65. }
  66. return ;
  67. }

接下来进入找规律环节,找个p的规律啊。

因为我比较傻,还以为这个还是和快速幂的拼凑有关的,就只去了打了2 4  16 256的值,很难发现规律

然后我每个都打了一次

k=0显而易见 1 2 3 4 5 6

k=1  1 2 ...

k=2  1 4 ...

反正你很快会发现就是这一项是C(i,2k-1+i)

所以你很想到组合数

但是直接求组合数可行么,是可行的,当然k很大,你不会玩

其实就是乘上新加的数,除以i,当然这个题目要除以逆元

  1. #include<stdio.h>
  2. const int N=,MD=1e9+;
  3. int a[N],b[N],v[N],n,k,i,j;
  4. int main()
  5. {
  6. v[]=b[]=;
  7. for(int i=;i<N;i++)v[i]=1LL*v[MD%i]*(MD-MD/i)%MD;
  8. while(scanf("%d",&n)!=EOF)
  9. {
  10. for(i=; i<n; i++)scanf("%d",&a[i]);
  11. scanf("%d",&k);
  12. long long t=*k;
  13. for(i=; i<n; i++,t++)b[i]=t*b[i-]%MD*v[i]%MD;
  14. for(i=n-; i>; i--)
  15. for(j=; j<=i; j++)a[i]=(a[i]+b[j]*1LL*a[i-j])%MD;
  16. for(i=; i<n; i++)printf(i==n-?"%d\n":"%d ",a[i]);
  17. }
  18. return ;
  19. }

TOJ4277: Sequence 组合数学的更多相关文章

  1. Sequence(组合数学,集合不同元素的个数)

    Sequence [组合数学] 时间限制: 3 Sec  内存限制: 128 MB 提交: 138  解决: 52 [提交][状态][讨论版] 题目描述 在某个夜黑月高的晚上,!!!,原谅我编不下去了 ...

  2. hdu(2062)-Subset sequence 组合数学

    意甲冠军:查找集合{1,2,3...n}第一m一个排列子. 收集的线索所行的大小. 例两个元素的排列子集合按字典树排列是:{1},{1,2},{2},{2,1}: 解法:一个一个元素来确定,每次把剩余 ...

  3. 2018 ACM-ICPC 区域赛(青岛站)题解整理

    题目链接 C - Flippy Sequence(组合数学+分类讨论) 两区间异或一下,分段考虑,如果全为0则任选两相同区间,答案为$C_{n+1}^{2}=\frac{n(n+1)}{2}$,只有一 ...

  4. BZOJ 1005 [HNOI2008] 明明的烦恼(组合数学 Purfer Sequence)

    题目大意 自从明明学了树的结构,就对奇怪的树产生了兴趣...... 给出标号为 1 到 N 的点,以及某些点最终的度数,允许在任意两点间连线,可产生多少棵度数满足要求的树? Input 第一行为 N( ...

  5. hdu4675 GCD of Sequence 莫比乌斯+组合数学

    /** 题目:hdu4675 GCD of Sequence 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4675 题意:给定n个数的a数组,以及m,k: ...

  6. bzoj 1005 组合数学 Purfer Sequence

    这题需要了解一种数列: Purfer Sequence 我们知道,一棵树可以用括号序列来表示,但是,一棵顶点标号(1~n)的树,还可以用一个叫做 Purfer Sequence 的数列表示 一个含有 ...

  7. poj 1019 Number Sequence 【组合数学+数字x的位宽函数】

    题目地址:http://poj.org/problem?id=1019 Number Sequence Time Limit: 1000MS   Memory Limit: 10000K Total ...

  8. hdu4908 &amp; BestCoder Round #3 BestCoder Sequence(组合数学)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4908 BestCoder Sequence Time Limit: 2000/1000 MS (Jav ...

  9. Codeforces 1264D - Beautiful Bracket Sequence(组合数学)

    Codeforces 题面传送门 & 洛谷题面传送门 首先对于这样的题目,我们应先考虑如何计算一个括号序列 \(s\) 的权值.一件非常显然的事情是,在深度最深的.是原括号序列的子序列的括号序 ...

随机推荐

  1. 【整站源码分享】分享一个JFinal3.4开发的整站源码,适合新手学习

    分享这个源码是14年开发上线的<威海创业者>站点的全套整站源码,前后端都在一个包里.当时开发使用的是JFinal1.4,最近改成了JFinal3.4.使用的JSP做的页面.有一定的参考价值 ...

  2. 登录控制 BaseController

    执行方法前 判断 sessin 登录信息 是否为空 ,空的话 返回 登录界面 并且给 LoginUser 赋值 public abstract class BaseController : Contr ...

  3. Linux环境下mysql的root密码忘记解决方法(2种)

    方法一: 1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库. 因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的 状态下,其他的用户也可以 ...

  4. 分享eclipse自动生成java注释方法

    设置方法介绍: eclipse中:Windows->Preferences->Java->Code Style->Code Template->Comments,然后对应 ...

  5. SQL Server 2016,2014 “无法找到数据库引擎启动句柄”

    当我决定安装SharePoint 2016 IT预览版时,我想我应该将它安装在Windows Server 2016技术预览版以及SQL Server 2016社区技术预览版(CTP)上.我敢打赌,你 ...

  6. 2015 ACM/ICPC Asia Regional Changchun Online Pro 1002 Ponds(拓扑排序+并查集)

    Ponds Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Sub ...

  7. Oracle中ROWID详解

    oracle数据库的表中的每一行数据都有一个唯一的标识符,或者称为rowid,在oracle内部通常就是使用它来访问数据的.rowid需要 10个字节的存储空间,并用18个字符来显示.该值表明了该行在 ...

  8. SpringMVC-请求参数的绑定

    绑定的机制 表单提交的数据都是k=v格式的 username=haha&password=123 SpringMVC的参数绑定过程是把表单提交的请求参数,作为控制器中方法的参数进行绑定的 要求 ...

  9. vue入坑教程(三)vue父子组件之间互相调用方法以及互相传递数据

    1.父组件调用子组件的方法 父组件: <template> <div> <button v-on:click="clickParent">点击& ...

  10. Bootstrap历练实例:带列表组的面板

    带列表组的面板 我们可以在任何面板中包含列表组,通过在 <div> 元素中添加 .panel 和 .panel-default 类来创建面板,并在面板中添加列表组.您可以从 列表组 一章中 ...