当前位置: 首页 > news >正文

2019 ICPC Greater New York Region J - Unicycles (规律+递推+矩阵快速幂)

题目链接


题目大意

给出如图所示那种正 n n n边形然后在中心添加一个点构成,现在需要找到一种 u n i c y c l e unicycle unicycle,定义为第 n n n个图的生成树再连接一条边,问 n n n边形有多少种 u n i c y c l e unicycle unicycle?

解题思路

比赛时没推到规律,空间想象力不强真的没有一点办法,先看题解怎么说吧:
在这里插入图片描述
最难的地方在 M ( i ) M(i) M(i)的基础上添加一个点推 M ( i + 1 ) M(i+1) M(i+1),一旦推出公式,我们得到:

M ( n ) = 1 , 3 , 8 , 21... M(n)=1,3,8,21... M(n)=1,3,8,21...

而斐波那契数列为:

F ( n ) = 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34... F(n)=1,1,2,3,5,8,13,21,34... F(n)=1,1,2,3,5,8,13,21,34...

不难发现对于 M ( i ) M(i) M(i),刚好对应斐波那契数列的 F ( 2 ∗ i ) F(2*i) F(2i),而如果对 M ( n ) M(n) M(n)求和得到前缀和 S ( n ) S(n) S(n)为: 1 , 4 , 12 , 33 , . . . 1,4,12,33,... 1,4,12,33,...
我们不难发现对于每个 S ( i ) S(i) S(i),对于斐波那契数列的 F ( 2 ∗ i + 1 ) − 1 F(2*i+1)-1 F(2i+1)1,那么对于上面的第 n n n个图, a n s = 1 , M ( 1 ) , M ( 2 ) , . . . M ( n − 1 ) ans={ 1,M(1),M(2),...M(n-1) } ans=1,M(1),M(2),...M(n1),而 S ( n − 1 ) = F ( 2 ∗ ( n − 1 ) + 1 ) − 1 S(n-1)=F(2*(n-1)+1)-1 S(n1)=F(2(n1)+1)1,最后再加上 1 1 1,那么最终的答案就是 n ∗ F ( 2 ∗ n − 1 ) n*F(2*n-1) nF(2n1),使用矩阵加速求解即可

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <math.h>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define lowbit(x) (x&(-x))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const double eps=1e-8;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const ll INF=1e18;
const int Mod=100007;
const int maxn=2e5+10;
struct Matrix{
    ll matrix[105][105];
};
int n;

Matrix mul(Matrix a,Matrix b){
    Matrix res;
    memset(res.matrix,0,sizeof res.matrix);
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
    for(int k=1;k<=n;k++){
        res.matrix[i][j]=(res.matrix[i][j]+(a.matrix[i][k]*b.matrix[k][j])%Mod)%Mod;
    }
    return res;
}

Matrix quick_pow(Matrix mx,ll x){
    Matrix ans;
    memset(ans.matrix,0,sizeof ans.matrix);
    for(int i=1;i<=n;i++) ans.matrix[i][i]=1;
    while(x){
        if(x&1) ans=mul(ans,mx);
        mx=mul(mx,mx);
        x>>=1;
    }
    return ans;
}

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int q;
    Matrix m; n=2;
    m.matrix[1][1]=1,m.matrix[1][2]=1;
    m.matrix[2][1]=1,m.matrix[2][2]=0;
    cin>>q;
    m=quick_pow(m,2*q-1);
    ll ans=m.matrix[2][1];
    cout<<(ans*q)%Mod<<endl;
    return 0;
}

相关文章:

  • WebLogic 9.2中文帮助网站公测中,欢迎大家访问!
  • 2019 ICPC Greater New York Region C - PassTheBuck(概率)
  • Oracle11gR2安装简介
  • 2019 ICPC Greater New York Region I - RationalBase(思维+进制转换)
  • 广告营销的创新
  • Educational Codeforces Round 86 C - Yet Another Counting Problem(规律+前缀和)
  • SQL Server2005重装Performance Monitor Counter Requirement错误解决
  • UVA1616 Caravan Robbers(二分答案+小数化分数)
  • UVA1619 Feel Good(链表+前缀和)
  • Codeforces Round #637 (Div. 2) D. Nastya and Scoreboard(位运算dfs/记忆化搜索)
  • Cocoa应用程序基本运行过程
  • 我们的内心都有伤痕
  • Codeforces Round #638 (Div. 2) B. Phoenix and Beauty (构造)
  • Codeforces Round #638 (Div. 2) C Phoenix and Distribution(思维/构造)
  • Mac Application GDB Usage
  • [译] 怎样写一个基础的编译器
  • ESLint简单操作
  • laravel5.5 视图共享数据
  • mysql 5.6 原生Online DDL解析
  • PermissionScope Swift4 兼容问题
  • Python socket服务器端、客户端传送信息
  • Redash本地开发环境搭建
  • RxJS 实现摩斯密码(Morse) 【内附脑图】
  • windows-nginx-https-本地配置
  • 干货 | 以太坊Mist负责人教你建立无服务器应用
  • 漂亮刷新控件-iOS
  • 入手阿里云新服务器的部署NODE
  • 一起来学SpringBoot | 第十篇:使用Spring Cache集成Redis
  • 最近的计划
  • 深度学习之轻量级神经网络在TWS蓝牙音频处理器上的部署
  • Java性能优化之JVM GC(垃圾回收机制)
  • k8s使用glusterfs实现动态持久化存储
  • linux 淘宝开源监控工具tsar
  • 选择阿里云数据库HBase版十大理由
  • ​​​​​​​​​​​​​​汽车网络信息安全分析方法论
  • ​软考-高级-系统架构设计师教程(清华第2版)【第1章-绪论-思维导图】​
  • "无招胜有招"nbsp;史上最全的互…
  • # include “ “ 和 # include < >两者的区别
  • (附源码)springboot炼糖厂地磅全自动控制系统 毕业设计 341357
  • (附源码)ssm高校志愿者服务系统 毕业设计 011648
  • (经验分享)作为一名普通本科计算机专业学生,我大学四年到底走了多少弯路
  • (未解决)jmeter报错之“请在微信客户端打开链接”
  • (转)AS3正则:元子符,元序列,标志,数量表达符
  • .NET : 在VS2008中计算代码度量值
  • .Net 访问电子邮箱-LumiSoft.Net,好用
  • .net知识和学习方法系列(二十一)CLR-枚举
  • /run/containerd/containerd.sock connect: connection refused
  • @test注解_Spring 自定义注解你了解过吗?
  • [ 常用工具篇 ] AntSword 蚁剑安装及使用详解
  • [android] 手机卫士黑名单功能(ListView优化)
  • [CC2642R1][VSCODE+Embedded IDE+IAR Build+Cortex-Debug] TI CC2642R1基于VsCode的开发环境
  • [CC-FNCS]Chef and Churu
  • [DAX] MAX函数 | MAXX函数
  • [JavaEE]线程的状态与安全
  • [MICROSAR Adaptive] --- Hello Adaptive World