/ Randle /

记录详情

Wrong Answer


  
# 状态 耗时 内存占用
#1 Wrong Answer 3ms 324.0 KiB
#2 Wrong Answer 3ms 332.0 KiB
#3 Wrong Answer 2ms 336.0 KiB
#4 Wrong Answer 1ms 328.0 KiB
#5 Wrong Answer 1ms 324.0 KiB
#6 Wrong Answer 1ms 340.0 KiB
#7 Wrong Answer 1ms 320.0 KiB
#8 Wrong Answer 1ms 328.0 KiB
#9 Wrong Answer 1ms 332.0 KiB
#10 Wrong Answer 1ms 332.0 KiB

代码

#include<cstdio>
#include<cstring>

typedef long long ll;
const int mod=1e9+7;

struct Mat
{
	int n;
	int m;
	ll num[2][2];
	Mat () {
		memset(num,0,sizeof(num));
	}
};

Mat operator * (Mat a,Mat b)
{
	Mat c;
	c.n=a.n;
	c.m=b.m;
	for(int i=0;i<c.n;++i)
	    for(int j=0;j<c.m;++j) {
	    	for(int k=0;k<a.m;++k)
    	    	c.num[i][j]=(c.num[i][j]+a.num[i][k]*b.num[k][j]%mod)%mod;
    //	    printf("%d\n",c.num[i][j]);
    	}
    return c;
}

Mat operator ^ (Mat a,int k)
{
	Mat b;
	b.n=a.n;
	b.m=a.m;
	for(int i=b.n;i>=0;--i)
	    b.num[i][i]=1;
    while(k) {
	    if(k&1)  b=b*a;
	    a=a*a;
	    k>>=1;
	}
	return b;
}

int main()
{
	Mat yuan;
    yuan.n=2;
    yuan.m=2;
    yuan.num[0][0]=1;
	yuan.num[0][1]=1;
	yuan.num[1][0]=1;
	yuan.num[1][1]=0;
    Mat fir;
    fir.n=1;
    fir.m=2;
    fir.num[0][0]=1;
    fir.num[0][1]=1;
    int q;
    scanf("%d",&q);
    Mat ask=yuan^(q-1);
    Mat ans=fir*ask;
    printf("%lld",ans.num[0][0]);
    return 0;
}

信息

递交者
类型
递交
题目
上楼梯(数据原创)
题目数据
下载
语言
C++
递交时间
2017-10-22 19:08:38
评测时间
2017-10-22 19:08:38
评测机
分数
0
总耗时
20ms
峰值内存
340.0 KiB