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,然后斜线上的值是一样的

矩阵快速幂代码

#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
const int N=,MD=1e9+,INF=0x3f3f3f3f;
const double eps=1e-,e=exp(),PI=acos(-.);
typedef long long ll;
int G;
struct MX
{
int v[N][N];
void O()
{
memset(v,,sizeof v);
}
void E()
{
memset(v,,sizeof v);
for(int i=; i<G; i++)
for(int j=i;j<G;j++)v[i][j]=j-i+;
}
void P()
{
for(int i=; i<G; i++)
for(int j=; j<G; j++)printf(j==G-?"%d\n":"%d ",v[i][j]);
}
MX operator+(const MX &b) const
{
MX c;
c.O();
for(int i=; i<G; i++)
for(int j=; j<G; j++)c.v[i][j]=v[i][j]+b.v[i][j];
return c;
}
MX operator*(const MX &b)const
{
MX c;
c.O();
for(int k=; k<G; k++)
for(int i=; i<G; i++)
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;
return c;
}
MX operator^(int p)const
{
MX y,x;
y.E(),memcpy(x.v,v,sizeof(v));
for(; p; x=x*x,p>>=)if(p&)y=y*x;
return y;
}
} a,ans;
int main()
{
//ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int n,k;
while(~scanf("%d",&n))
{
G=n;
a.O();
for(int i=; i<n; i++)scanf("%d",&a.v[][i]);
scanf("%d",&k);
ans.E();
ans=ans^(k-);
ans=a*ans;
for(int i=; i<n; i++)printf(i==G-?"%d\n":"%d ",ans.v[][i]);
}
return ;
}

接下来进入找规律环节,找个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,当然这个题目要除以逆元

#include<stdio.h>
const int N=,MD=1e9+;
int a[N],b[N],v[N],n,k,i,j;
int main()
{
v[]=b[]=;
for(int i=;i<N;i++)v[i]=1LL*v[MD%i]*(MD-MD/i)%MD;
while(scanf("%d",&n)!=EOF)
{
for(i=; i<n; i++)scanf("%d",&a[i]);
scanf("%d",&k);
long long t=*k;
for(i=; i<n; i++,t++)b[i]=t*b[i-]%MD*v[i]%MD;
for(i=n-; i>; i--)
for(j=; j<=i; j++)a[i]=(a[i]+b[j]*1LL*a[i-j])%MD;
for(i=; i<n; i++)printf(i==n-?"%d\n":"%d ",a[i]);
}
return ;
}

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. 数据库limit子句

    limit子句:用来限定语句执行结果的偏移量,有一个或者两个参数:第一个参数表示返回结果首行偏移量,第二个参数表示最大返回行数.例如:SELECT * FROM employees ORDER BY ...

  2. userBean的删除

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...

  3. 【Orange Pi Lite2】 ——1《如何开始使用开源硬件》

    [Orange Pi Lite2] --1<如何开始使用开源硬件> 本文只在博客园发布 在开始前你需要准备的材料与软件 用户手册_Orange Pi Lite2 OrangePi_Lite ...

  4. 重温Javascript(三)-继承

    继承 1.原型链继承 基本思想是利用原型让一个引用类型继承另一个引用类型的属性和方法.每个构造函数都有一个原型对象,原型对象都包含一个指向构造函数的指针,而实例都包含一个指向原型对象的内部指针.让原型 ...

  5. caffe parse_log.sh

    画loss曲线需要用到此shell脚本 #!/bin/bash # Usage parse_log.sh caffe.log # It creates the following two text f ...

  6. 查看nvidia的GPU

    nvidia-smi就可以查看,可以看到进程的占用率,可以kill杀掉进程 注意这里的-前后都不要空格,连起来写

  7. typescript设置全屏

    fullScreen() { document.getElementById("fullScreen").style.display = "none"; doc ...

  8. c#中接口、抽象类、继承综合小练习

    namespace Test { class Program { static void Main(string[] args) { //作业:橡皮rubber鸭子.木wood鸭子.真实的鸭子real ...

  9. PAT (Basic Level) Practise (中文)- 1013. 数素数 (20)

    http://www.patest.cn/contests/pat-b-practise/1013 令Pi表示第i个素数.现任给两个正整数M <= N <= 104,请输出PM到PN的所有 ...

  10. 关于flyme5显示不到和卸载不到旧应用解决方法

    笔者买入一台mx5,升级flyme5后旧应用没有显示出来,而且在设置的应用管理都没显示旧应用. 通过adb命令: adb shell pm list packages显示所有包名, 查看自己要删除应用 ...