矩阵两道题目codeforces 450B 和hdu 5015

本文探讨了233矩阵的构造与求解方法,通过递归与矩阵运算解决复杂序列计算问题,同时分享了在算法实现过程中的细节处理与优化技巧。

233 matrix

In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233333 ... in the same meaning. And here is the question: Suppose we have a matrix called 233 matrix. In the first line, it would be 233, 2333, 23333... (it means a 0,1 = 233,a 0,2 = 2333,a 0,3 = 23333...) Besides, in 233 matrix, we got a i,j = a i-1,j +a i,j-1( i,j ≠ 0). Now you have known a 1,0,a 2,0,...,a n,0, could you tell me a n,m in the 233 matrix?

Input

There are multiple test cases. Please process till EOF.

For each case, the first line contains two postive integers n,m(n ≤ 10,m ≤ 10 9). The second line contains n integers, a 1,0,a 2,0,...,a n,0(0 ≤ a i,0 < 2 31).

Output

For each case, output a n,m mod 10000007.

Sample Input

1 1
1
2 2
0 0
3 7
23 47 16

Sample Output

234
2799
72937


        
  

Hint


 

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int modn=1e7+7; 
const int maxn=15;
#define ll long long 
ll n,m;
struct node{
    ll s[maxn][maxn];
    node(){
        memset(s,0,sizeof(s));
    }
};
node multi(node a,node b){
    node t;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++){
                t.s[i][j]=(t.s[i][j]+a.s[i][k]*b.s[k][j]%modn+modn)%modn;
            }
        }
    }
    return t;
}
node quick(node a,ll nn){
    node res;
    for(int i=0;i<n;i++){
        res.s[i][i]=1;
    }
    while(nn){
        if(nn&1) res=multi(res,a);
        a=multi(a,a);
        nn>>=1;
    }
    return res;
    
}
int main(){
    while(scanf("%lld%lld",&n,&m)!=EOF){
        ll a[15]; node b;
        for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        }
        a[0]=23;
        a[n+1]=3;
        n++;
        n++;
        for(int i=0;i<n;i++){
            if(i!=n-1) b.s[i][0]=10;
            for(int j=1;j<=i;j++){
                if(i!=n-1)
                b.s[i][j]=1;
            }
            b.s[i][n-1]=1;
        }
/*        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cout<<b.s[i][j]<<" ";
            } 
            cout<<endl;
        }*/
        node res=quick(b,m);
        //b[n-1][n-1]=1;
        ll ans=0;
    /*        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cout<<res.s[i][j]<<" h";
            } 
            cout<<endl;
        }*/
        for(int i=0;i<n;i++){
            ans=(a[i]*(res.s[n-2][i])%modn+ans)%modn;
        //    cout<<a[i]<<" "<<res.s[n-2][i]<<"wer"<<endl;
        }
        cout<<ans<<endl;
    }
    return 0;
}

这道题目,怎么说呢,递归的话,很有可能用矩阵,我直接找规律,又忘记了复杂度过不了了

还有细节问题,快速幂,稍微推一下就行了

jzzhu and sequences

Jzzhu has invented a kind of sequences, they meet the following property:

You are given x and y, please calculate fn modulo 1000000007 (109 + 7).

Input

The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109).

Output

Output a single integer representing fn modulo 1000000007 (109 + 7).

Examples

Input

2 3
3

Output

1

Input

0 -1
2

Output

1000000006

Note

In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1.

In the second sample, f2 =  - 1;  - 1 modulo (109 + 7) equals (109 + 6).

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
const int modn=1e9+7;
struct node{
	ll m[2][2];
	node(){
		memset(m,0,sizeof(m));
	}
};
node multi(node a,node b){
	node res;
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++) 
		res.m[i][j]=0;
	}
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<2;k++){
				res.m[i][j]=(ll)((ll)(a.m[i][k]*b.m[k][j]+modn)+res.m[i][j])%modn;
			//	cout<<a.m[i][k]<<" "<<b.m[k][j]<<" "<<res.m[i][j]<<" "<<i<<" "<<j<<"end"<<endl;
			}
		}
	}
//	cout<<res.m[0][0]<<" "<<res.m[0][1]<<" "<<res.m[1][0]<<"f "<<res.m[1][1]<<endl;
	return res;
}
//node res;
node  qui(node r,int n){
	node res;
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++) 
		res.m[i][j]=0;
	}
	for(int i=0;i<2;i++){
		res.m[i][i]=1;
	}
	res.m[0][1]=0;
	res.m[1][0]=0;
	while(n){
	//	cout<<n<<"res"<<endl;
		if(n&1)
		res=multi(res,r); 
	//	cout<<res.m[0][1]<<"ans"<<endl;
		r=multi(r,r);
		n>>=1;
	}
	
	return res;
}
//ll a[2][2];
int main(){
	ll x,y,n;
while(	scanf("%lld%lld%lld",&x,&y,&n)!=EOF)
{

	node a;
	node b;
	b.m[0][0]=x;
	b.m[0][1]=y;
	a.m[0][1]=-1;
	a.m[1][0]=1;
	a.m[1][1]=1; 
	a.m[0][0]=0;	
	if(n==2){
		cout<<(y%modn+modn)%modn<<endl;
		return 0;
	}
	if(n==1){
		cout<<(x%modn+modn)%modn<<endl;
		return 0;
	}
	
	node res=qui(a,n-2);
	//res=multi(b,res);
	ll ans=(ll)((ll)(res.m[0][1]*x)%modn+(ll)(res.m[1][1]*y)%modn)%modn;
	
	if(ans<0) ans+=modn; 
	if(ans<0) ans+=modn;
	cout<<ans<<endl;
//	cout<<(res.m[0][1]+modn)%modn<<endl;
}
	return 0;
} 

这道题目忘了用longlong了一直wa, 差点把我劝退了。

总之,细节问题,很扎心

 

这个是完整源码 python实现 Django 【python毕业设计】基于Python的天气预报(天气预测分析)(Django+sklearn机器学习+selenium爬虫)可视化系统.zip 源码+论文+sql脚本 完整版 数据库是mysql 本研究旨在开发一个基于Python的天气预报可视化系统,该系统结合了Django框架、sklearn机器学习库Selenium爬虫技术,实现对天气数据的收集、分析可视化。首先,我们使用Selenium爬虫技术从多个天气数据网站实时抓取气象数据,包括温度、湿度、气压、风速等多项指标。这些数据经过清洗预处理后本研究旨在开发一个基于Python的天气预报可视化系统,该系统结合了Django框架、sklearn机器学习库Selenium爬虫技术,实现对天气数据的收集、分析可视化。首先,我们使用Selenium爬虫技术从多个天气数据网站实时抓取气象数据,包括温度、湿度、气压、风速等多项指标。这些数据经过清洗预处理后,将其存储在后端数据库中,以供后续分析。 其次,采用s,将其存储在后端数据库中,以供后续分析。 其次,采用sklearn机器学习库构建预测模型,通过时间序列分析回归方法,对未来天气情况进行预测。我们利用以往的数据训练模型,以提高预测的准确性。通过交叉验证超参数优化等技术手段,我们优化了模型性能,确保其在实际应用中的有效性可靠性。 最后,基于Django框架开发前端展示系统,实现天气预报的可视化。用户可以通过友好的界面查询实时天气信息未来几天内的天气预测。系统还提供多种图表类型,包括折线图柱状图,帮助用户直观理解天气变化趋势。 本研究的成果为天气预报领域提供了一种新的技术解决方案,不仅增强了数据获取处理的效率,还提升了用户体验。未来,该系统能够扩展至其他气象相关的应用场景,为大众提供更加准确及时的气象服务。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值