zoukankan      html  css  js  c++  java
  • codevs 4247

    当时不会矩乘,所以退出是个明智的选择。。。

    会矩乘后这题就很容易了。。。注意超longlong和y>x就可以了。。。

     1 #include<bits/stdc++.h>
     2 #define inc(i,l,r) for(i=l;i<=r;i++)
     3 #define dec(i,l,r) for(i=l;i>=r;i--)
     4 #define mem(a) memset(a,0,sizeof(a))
     5 #define ll long long
     6 #define succ(x) (1<<x)
     7 using namespace std;
     8 ll read(){
     9     ll x=0,f=1;char ch=getchar();
    10     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    11     while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    12     return x*f;
    13 }
    14 struct mat{
    15     ll n,m;
    16     ll a[20][20];
    17 }a,b,tmp;
    18 ll k,x,inf,i;
    19 mat operator*(const mat&x,const mat&y){
    20     mat s;
    21     int i,j,k;
    22     mem(s.a);
    23     s.n=x.n;s.m=y.m;
    24     inc(i,1,s.n)
    25     inc(j,1,s.m)
    26     inc(k,1,x.m){
    27         ll t=(ll)sqrt(y.a[k][j]),v=x.a[i][k];
    28         v=v*t%inf;
    29         v=v*t%inf;
    30         t=t*t;
    31         v=(v+(y.a[k][j]-t)*x.a[i][k]%inf)%inf;
    32         (s.a[i][j]+=v)%=inf;
    33     }
    34     return s;
    35 }
    36 mat mul(ll k){
    37     mat s=a,t=a;
    38     k--;
    39     while(k>0){
    40         if(k%2)s=s*t;
    41         t=t*t;k/=2;
    42     }
    43     return s;
    44 }
    45 int main(){
    46     k=read();x=read();x-=read();inf=read();
    47     mem(a.a);a.n=a.m=k;
    48     inc(i,1,k)a.a[k][k-i+1]=read();
    49     inc(i,1,k-1)
    50     a.a[i][i+1]=1;
    51     b.a[k][1]=1;
    52     b.n=k;b.m=1;
    53     if(x<0){
    54         printf("0
    ");
    55         return 0;
    56     }
    57     tmp=mul(x);
    58     b=tmp*b;
    59     printf("%lld
    ",b.a[k][1]);
    60     return 0;
    61 }
    View Code
  • 相关阅读:
    线段树
    坐标离散化
    超大背包问题
    折半枚举 双向搜索
    弹性碰撞
    反转 开关问题
    尺取法
    二分法
    最小生成树
    区间素数筛法
  • 原文地址:https://www.cnblogs.com/onlyRP/p/4883713.html
Copyright © 2011-2022 走看看