ACM 矩阵乘法 SPOJ AMR10E Stocks Prediction

本文介绍了一个用于预测商店库存销售情况的模型,并提供了一种算法来计算特定周期内预测销售额的总和,通过矩阵快速幂的方式提高了计算效率。

http://www.spoj.com/problems/AMR10E/

E - Stocks Prediction
Time Limit:8000MS     Memory Limit:KB     64bit IO Format:%lld & %llu

Description

The department store where my family goes shopping is trying to predict how much of each item they stock they will sell each month.  Keeping a large amount of inventory is costly, and running out of items is also not a good idea.  Since the manager asked for my help as a sales consultant, I decided to formulate a model for predicting each month's sales S of an item based on its sales during the previous R months.  After a lot of trial and error, I came up with such a model, where 
S(n) = a1*S(n-1) + a2*S(n-2) + ... + aR*S(n-R)  
where S(n) is the predicted sales for the nth month for n > R, and S(1) to S(R) are seed values. 
 
The store manager was pleased with my model's ability to help him in controlling his inventory.  
He asked me to list out every Kth month's sales, and give him the sum of the first N values from this list.  For example he wanted every Christmas month's sales summed up for the next 10 years (N=10 and K=12, month 1 being January), or every end-of-quarter month's sales for the next 2 years (N=2, K=3). 
 
Can you please help me write a program that does all the above? 
 
INPUT 
The first line of the input T, the number of test cases. Each test case consists of three lines. 
The first line of each test case contains N, R, K. 
The second line of each test case contains R integers denoting S(1), S(2), ..., S(R). 
The third line of each test case contains R integers denoting the coefficients a1, a2, ..., aR of the predictive model. 
 
OUTPUT 
For each test case, output the sum requested by the manager as given in the problem statement, modulo 1,000,000,007. 
 
CONSTRAINTS 
T <= 40 
1 <= N <= 1000000000 
1 <= R <= 8 
1 <= K <= 8 
0 <= All other input values < 1000000007 
 
SAMPLE INPUT 

4 1 1 
1  
2  
3 2 3 
1 1  
1 1  
 
SAMPLE OUTPUT 
15 
44 
 
EXPLANATION 
In the first test case, it is given that S(1) = 1 and the relation is S(n)=2*S(n-1). The list asked by the store manager consists of all the terms of S since K is 1. Hence, the answer is just the sum of the first 4 terms of S. 
In the second test case, the sequence S is the fibonacci sequence which is: 1, 1, 2, 3, 5, 8, 13, 21, 34. The list consists of 2, 8, 34 which sum up to 44.


转移矩阵为a

先将分为每组k次,算a^k //a=quick(a,k);

再算(a^k)^k //a=quick(a,n);

<strong>Memory: </strong>2662 KB<strong>Time: </strong>170 MS<strong>Language: </strong>C++ (g++ 4.3.2)<strong>Result: </strong><span style="color:blue;">Accepted</span>
/*
 * Author: NICK WONG
 * Created Time:  7/30/2014 16:45:37
 * File Name: 
 */
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
#define out(x) cout<<#x<<": "<<x<<endl
const double eps(1e-8);
const int maxn=10100;
const long long maxint=-1u>>1;
const long long maxlong=maxint*maxint;
typedef long long lint;
const lint mod=1000000007;
lint ans;
int n,r,k,p[20];
lint s[200];

struct matrix
{
    lint m[10][10];
    matrix()
    {
        memset(m,0,sizeof(m));//注意要清零
    }
};

matrix operator * (const matrix & a,const matrix & b)
{
    matrix c;
    for (int i=1; i<=9; i++)
        for (int j=1; j<=9; j++)
        {
            c.m[i][j]=0;
            for (int k=1; k<=9; k++)
                c.m[i][j]=(c.m[i][j]+a.m[i][k]*b.m[k][j])%mod;
        }
    return c;
}

matrix quick(matrix base,int pow)
{
    matrix a;
    for (int i=1; i<=9; i++) a.m[i][i]=1;//单位阵,矩阵乘法时要用到
    while (pow)
    {
        if (pow&1) a=a*base;
        base=base*base;
        pow>>=1;
    }
    //if (pow==0) return base;
    return a;
}
            
void init()
{
    memset(s,0,sizeof(s));
    cin>>n>>r>>k;
    for (int i=1; i<=r; i++) cin>>s[i];
    for (int i=1; i<=r; i++) cin>>p[i];
}

void work()
{
    for (int i=r+1; i<=80; i++)
    {
        for (int j=1; j<=r; j++) s[i]=(s[i]+p[j]*s[i-j])%mod;
    }
    matrix a,wjj;
    for (int i=1; i<=8; i++) wjj.m[1][i]=s[i];
    for (int i=1; i<=7; i++) a.m[i+1][i]=1;
    for (int i=1; i<=r; i++) a.m[8-i+1][8]=p[i];
    a=quick(a,k);
    a.m[k][9]=a.m[9][9]=1;
    a=quick(a,n);
    wjj=wjj*a;
    ans=wjj.m[1][9];
    cout<<ans<<endl;  
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {   
        init();
        work();
    }
    return 0;
}




内容概要:本文详细阐述了工业母机技术领域中“高级结构设计工程师”这一岗位的全方位任职要求与职业发展路径,涵盖职位对标、目标企业、学历与证书要求、年龄范围、管理半径、晋升关键点、必备工作经验年限以及薪资待遇区间。重点突出该岗位对高端数控机床核心结构(如床身、主轴箱、导轨等)设计能力的要求,强调有限元分析、精度控制、热变形补偿、振动抑制等核心技术能力,并明确指出需具备项目主导经验、团队管理能力和跨部门协作经验。同时,根据不同企业类型和发展阶段,给出了清晰的年薪划分标准,体现了市场对该岗位的技术深度与综合能力的高度认可。; 适合人群:具备5年以上工业母机或高端机床结构设计经验,致力于向高级工程师、技术专家或管理岗位发展的结构设计从业者;或希望转型进入高端装备制造业的精密机械研发人员。; 使用场景及目标:①用于求职者精准定位职业发展方向,评估自身与高级岗位之间的能力差距;②辅助企业制定人才招聘标准与薪酬体系;③指导技术人员规划技能提升路径,聚焦核心技术积累与项目经验沉淀。; 阅读建议:建议结合个人职业发展阶段对照文中各项指标进行自我诊断,重点关注“晋升关键点”与“必备年限”部分,有针对性地补齐技术短板、积累主导项目经验,并注重专利成果与团队管理能力的培养,以全面提升竞争力。
源码下载地址: https://pan.quark.cn/s/a92ed831069e ### Jmeter工具对验证码的处理方法 #### 一、引言 随着互联网应用安全性的不断提升,验证码已成为网站登录流程中的关键环节。然而,对于性能测试工程师而言,如何高效利用JMeter工具处理登录过程中的验证码构成了一项挑战。本文将系统性地阐述在JMeter中配置和处理验证码的方法,旨在帮助读者熟练掌握这一技能。 #### 二、JMeter中处理验证码的方法与步骤 ##### 1. 创建线程组 在JMeter中构建一个线程组,该线程组将作为执行测试的起始点。在此线程组内,需要添加各类采样器、监听器及其他必要组件,以模拟用户的登录行为。 ##### 2. 新建获取验证码的HTTP请求 在已创建的线程组中,添加一个HTTP请求采样器来模拟用户获取验证码的操作。特别需要注意的是,若目标网站的验证码以图片形式呈现,必须配置正确的HTTP请求以获取该图片。 ##### 3. 配置后置处理器解析验证码 由于通过HTTP请求无法直接获取验证码的值,因此需要增设一个后置处理器实现这一功能。推荐采用BeanShell Post Processor,这是一种高度灵活的脚本编写方式,能够充分满足解析验证码的需求。具体的代码实现可参考以下链接:[http://blog.csdn.net/xreztento/article/details/48682923](http://blog.csdn.net/xreztento/article/details/48682923)。 在BeanShell Post Processor中,需编写一段代码来解析获取到的验证码图片,并将其保存至JMeter的用户自...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值