zoukankan      html  css  js  c++  java
  • [codeforces821E]Okabe and El Psy Kongroo

    题意:(0,0)走到(k,0),每一部分有一条线段作为上界,求方案数。

    解题关键:dp+矩阵快速幂,盗个图,注意ll

    关于那条语句为什么不加也可以,因为我的矩阵C,就是因为多传了了len的原因,其他位置都是0,所以不需要加

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<cstdlib>
     4 #include<algorithm>
     5 #include<cmath>
     6 #include<iostream>
     7 using namespace std;
     8 typedef long long ll;
     9 const ll mod=1e9+7;
    10 struct mat{
    11     ll m[17][17];
    12 }A;
    13 
    14 mat mul(mat &A,mat &B,ll len){
    15     mat C={0};
    16     for(int i=0;i<=len;i++){
    17         for(int k=0;k<=len;k++){
    18             for(int j=0;j<=len;j++){
    19                 C.m[i][j]=(C.m[i][j]+A.m[i][k]*B.m[k][j]%mod+mod)%mod;
    20             }
    21         }
    22     }
    23     return C;
    24 }
    25 
    26 mat mod_pow(mat A,ll n,ll len){
    27     mat B={0};
    28     for(int i=0;i<=len;i++) B.m[i][i]=1;
    29     while(n>0){
    30         if(n&1) B=mul(B,A,len);
    31         A=mul(A,A,len);
    32         n>>=1;
    33     }
    34     return B;
    35 }
    36 
    37 int main(){
    38     ll n,k;
    39     ios::sync_with_stdio(0);
    40     cin.tie(0);
    41     cout.tie(0);
    42     for(int i=0;i<16;i++){
    43         int j=i-1>=0?i-1:0;
    44         for(;j<=i+1&&j<16;j++){
    45             A.m[i][j]=1;
    46         }
    47     }
    48     mat C;
    49     cin>>n>>k;
    50     mat B={0};
    51     B.m[0][0]=1;
    52     ll cnt=0;
    53     for(int i=0;i<n&&cnt<k;i++){
    54         ll a,b,c;
    55         cin>>a>>b>>c;
    56         if(b>k) b=k;
    57         cnt+=b-a;
    58         C=mod_pow(A, b-a, c);
    59         B=mul(B, C, c);
    60         for(ll j=c+1;j<16;j++) B.m[j][0]=0;//这句话不加也可以,为什么?
    61     }
    62     cout<<(B.m[0][0]+mod)%mod<<"
    ";
    63     return 0;
    64 }
  • 相关阅读:
    DDL讲解
    hadoop-04
    hadoop03
    记录一次hadoop自己 埋的坑
    flask_apscheduler一款定时任务器
    flask通过内存导出excel
    Matplotlib不能显示中文问题
    hadoop02
    hadoop常见shell命令
    hadoop1
  • 原文地址:https://www.cnblogs.com/elpsycongroo/p/7352468.html
Copyright © 2011-2022 走看看