TOJ4277: Sequence 组合数学
4277: Sequence
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
看似矩阵快速幂,但是这个矩阵是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 组合数学的更多相关文章
- Sequence(组合数学,集合不同元素的个数)
Sequence [组合数学] 时间限制: 3 Sec 内存限制: 128 MB 提交: 138 解决: 52 [提交][状态][讨论版] 题目描述 在某个夜黑月高的晚上,!!!,原谅我编不下去了 ...
- hdu(2062)-Subset sequence 组合数学
意甲冠军:查找集合{1,2,3...n}第一m一个排列子. 收集的线索所行的大小. 例两个元素的排列子集合按字典树排列是:{1},{1,2},{2},{2,1}: 解法:一个一个元素来确定,每次把剩余 ...
- 2018 ACM-ICPC 区域赛(青岛站)题解整理
题目链接 C - Flippy Sequence(组合数学+分类讨论) 两区间异或一下,分段考虑,如果全为0则任选两相同区间,答案为$C_{n+1}^{2}=\frac{n(n+1)}{2}$,只有一 ...
- BZOJ 1005 [HNOI2008] 明明的烦恼(组合数学 Purfer Sequence)
题目大意 自从明明学了树的结构,就对奇怪的树产生了兴趣...... 给出标号为 1 到 N 的点,以及某些点最终的度数,允许在任意两点间连线,可产生多少棵度数满足要求的树? Input 第一行为 N( ...
- hdu4675 GCD of Sequence 莫比乌斯+组合数学
/** 题目:hdu4675 GCD of Sequence 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4675 题意:给定n个数的a数组,以及m,k: ...
- bzoj 1005 组合数学 Purfer Sequence
这题需要了解一种数列: Purfer Sequence 我们知道,一棵树可以用括号序列来表示,但是,一棵顶点标号(1~n)的树,还可以用一个叫做 Purfer Sequence 的数列表示 一个含有 ...
- poj 1019 Number Sequence 【组合数学+数字x的位宽函数】
题目地址:http://poj.org/problem?id=1019 Number Sequence Time Limit: 1000MS Memory Limit: 10000K Total ...
- hdu4908 & BestCoder Round #3 BestCoder Sequence(组合数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4908 BestCoder Sequence Time Limit: 2000/1000 MS (Jav ...
- Codeforces 1264D - Beautiful Bracket Sequence(组合数学)
Codeforces 题面传送门 & 洛谷题面传送门 首先对于这样的题目,我们应先考虑如何计算一个括号序列 \(s\) 的权值.一件非常显然的事情是,在深度最深的.是原括号序列的子序列的括号序 ...
随机推荐
- 22/tcp open|filtered ssh 80/tcp open|filtered http
22/tcp open|filtered ssh80/tcp open|filtered http nmap不能确定该端口是打开还是过滤,这可能是扫描一个打开的端口,但没有回应.
- 【Python图像特征的音乐序列生成】深度卷积网络,以及网络核心
这个项目主要涉及到两个网络,其中卷积神经网络用来提取图片表达的情绪,提取出一个二维向量. 网络结构如图: 词向量采用预训练的glove模型,d=50,其他信息包括了图片的“空旷程度”.亮度.对比度等信 ...
- python爬虫之路——正则表达式初识
正则表达式:是一个特殊的符号系列,检查字符串是否与指定模式匹配. python中的re模块拥有全部的正则表达式功能. 判断字符: 类型: 数目:有无: 个数:单值 区间 离散 判 ...
- 认识CoreData—初识CoreData
http://www.cocoachina.com/ios/20160729/17245.html 这段时间公司一直比较忙,和组里小伙伴一起把公司项目按照之前逻辑重写了一下.由于项目比较大,还要兼顾之 ...
- Django form组件应用
form 组件的使用 class Register(forms.Form): user = forms.CharField(min_length=2, widget=widgets.TextInput ...
- Trie入门讲解
我们常常用Trie(也叫前缀树)来保存字符串集合.如下图所示就是一个Trie. 上图表示的字符串集合为$\{a,to,tea,ted,ten,i,in,inn \}$,每个单词的结束位置对应一个“单词 ...
- vue2使用animate css
先上几个链接 vue插件大集合:awesome-vue vue2插件: vue2-animate:vue2-animate vue2插件vue2-animateDEMO: vue2-animatede ...
- python_97_类的继承2
# 经典类与新式类差别主要体现在多继承上 #多继承是从左到有 class People():#经典类 #class People(object):#新式类 def __init__(self,name ...
- spring-data-JPA源码解读
spring-data-JPA源码部分有两个很重要的部分:1.识别repositories接口 2.将接口添加代理实现类并托管spring管理 JpaRepositoriesRegistrar 目的是 ...
- EWS code return Error : Request failed. The remote server returned an error: (403) Forbidden OR (401) Unauthorized
Following is my code. ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1 ...