首页 技术 正文
技术 2022年11月19日
0 收藏 891 点赞 4,780 浏览 1354 个字

题目看了半天没看懂,,就是把一个数列更新r次,每次更新就是计算和,就是每一个数,只要出现了的表号都要加上去,具体看代码

矩阵快速幂实现加速

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;const double g=10.0,eps=1e-;
const int N=+,maxn=<<+,inf=0x3f3f3f3f;struct Node{
ll row,col;
ll a[N][N];
};
Node mul(Node x,Node y)
{
Node ans;
ans.row=x.row,ans.col=y.col;
memset(ans.a,,sizeof ans.a);
for(ll i=;i<x.row;i++)
for(ll j=;j<x.col;j++)
for(ll k=;k<y.col;k++)
ans.a[i][k]=(ans.a[i][k]+x.a[i][j]*y.a[j][k]+mod)%mod;
return ans;
}
Node quick_mul(Node x,ll n)
{
Node ans;
ans.row=x.row,ans.col=x.col;
memset(ans.a,,sizeof ans.a);
for(ll i=;i<ans.col;i++)ans.a[i][i]=;
while(n){
if(n&)ans=mul(ans,x);
x=mul(x,x);
n>>=;
}
return ans;
}
int main()
{ ios::sync_with_stdio(false);
cin.tie();
// cout<<setiosflags(ios::fixed)<<setprecision(2);
ll t,n,r;
cin>>t;
while(t--){
cin>>n>>r;
Node A;
A.row=n,A.col=;
for(ll i=;i<n;i++)cin>>A.a[i][];
Node B;
B.row=n,B.col=n;
memset(B.a,,sizeof B.a);
for(ll i=;i<n;i++)
{
ll k,s;
cin>>k;
while(k--){
cin>>s;
B.a[i][s]=;
}
}
/* for(ll i=0;i<n;i++)
{
for(ll j=0;j<n;j++)
cout<<B.a[i][j]<<" ";
cout<<endl;
}*/
A=mul(quick_mul(B,r),A);
for(ll i=;i<n;i++)cout<<A.a[i][]<<(i==n- ? '\n' : ' ');
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,020
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,359
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,142
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,772
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,850