http://acm.hdu.edu.cn/showproblem.php?pid=6198

F0=0,F1=1的斐波那契数列。

给定K,问最小的不能被k个数组合而成的数是什么。

赛后才突然醒悟,只要间隔着取k+1个数,显然根据斐波那契数列规律是不存在把其中两个数相加的结果又出现在数列中的情况(有特别的看下面),不就不会被组合出来了么?

这里有1 3 8...这种和1 2 5 13...两种,但因为后者任意一位的1,2可以被转化为3,这是唯一一种特例,所以我们采用前者。构造矩阵快速幂一下。

#include <cstdio>
#include <string>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#define LL long long
using namespace std;
const LL N = ;
const LL mod = ;
LL n;
struct mx
{
LL n, m;
LL c[][];//需要根据题目开大
void initMath(LL _n)//初始化方阵
{
m = n = _n;
}
void initOne(LL _n)//初始化单位矩阵
{
m = n = _n;
for (LL i = ; i<n; i++)
for (LL j = ; j<m; j++)
c[i][j] = (i == j);
}
void print()//测试打印
{
for (LL i = ; i<n; i++)
{
for (LL j = ; j<m; j++)
cout << c[i][j] << ' ';
cout << endl;
}
}
};
mx Mut(mx a, mx b)
{
mx c;
c.n = a.n, c.m = b.m;
for (LL i = ; i<a.n; i++)
for (LL j = ; j<b.m; j++)
{
LL sum = ;
for (LL k = ; k<b.n; k++)
sum += a.c[i][k] * b.c[k][j], sum %= mod;
c.c[i][j] = sum;
}
return c;
}
mx fastMi(mx a, LL b)
{
mx mut; mut.initOne(a.n);
while (b)
{
if (b % != )
mut = Mut(mut, a);
a = Mut(a, a);
b /= ;
}
return mut;
}
int main()
{
cin.sync_with_stdio(false);
LL m;
while (cin>>m>>n)
{
if (n == )cout << << endl;
else if (n == )
{
cout << m << endl;
}
else
{
cout << n * (m - n) + n << endl;
}
}
return ;
}

hdu number number number 斐波那契数列 思维的更多相关文章

  1. HDU 1005 Number Sequence【斐波那契数列/循环节找规律/矩阵快速幂/求(A * f(n - 1) + B * f(n - 2)) mod 7】

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  2. python基础----斐波那契数列

    python实现斐波那契数列的三种方法 """ 斐波那契数列 0,1,1,2,3,5,8,13,21,... """ # 方法一:while ...

  3. 509. Fibonacci Number斐波那契数列

    网址:https://leetcode.com/problems/fibonacci-number/ 原始的斐波那契数列 运用自底向上的动态规划最佳! 可以定义vector数组,但是占用较多内存空间 ...

  4. 剑指offer--4.斐波那契数列

    int最大范围(有符号情况下,从第0项0开始)能取到第46项1836311903,47项溢出 时间限制:1秒 空间限制:32768K 热度指数:473928 题目描述 大家都知道斐波那契数列,现在要求 ...

  5. HDU 1316 (斐波那契数列,大数相加,大数比较大小)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1316 Recall the definition of the Fibonacci numbers: ...

  6. hdu 5914(斐波拉契数列)

    Triangle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  7. SPOJ 5152 Brute-force Algorithm EXTREME && HDU 3221 Brute-force Algorithm 快速幂,快速求斐波那契数列,欧拉函数,同余 难度:1

    5152. Brute-force Algorithm EXTREME Problem code: BFALG Please click here to download a PDF version ...

  8. HDU 1715 (大数相加,斐波拉契数列)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1715 大菲波数 Time Limit: 1000/1000 MS (Java/Others)     ...

  9. hdu 4549 M斐波那契数列(快速幂 矩阵快速幂 费马小定理)

    题目链接http://acm.hdu.edu.cn/showproblem.php?pid=4549: 题目是中文的很容易理解吧.可一开始我把题目看错了,这毛病哈哈. 一开始我看错题时,就用了一个快速 ...

随机推荐

  1. Nikto

    https://cirt.net/nikto2 Fire Up Kali & Open Nikto Let's fire up Kali and get started with nikto. ...

  2. topcoder srm 490 div1

    problem1 link 首先每$n*m$一定是一个循环,所以只需要考虑时间$[0,n*m-1]$即可.这个期间一共出现了$n$个,第i个的出现时间为$m*i$,离开的时间为$\left \lcei ...

  3. 配置Codeblocks

    1.安装mingw 官网:http://www.mingw.org/找到左边Navigation里面的Download(选择下图第一个即可,安装管理器,可自己手动选择要安装的组件)下图是安装管理器界面 ...

  4. HDU 4366 Successor(dfs序 + 分块)题解

    题意:每个人都有一个上司,每个人都有能力值和忠诚值,0是老板,现在给出m个询问,每次询问给出一个x,要求你找到x的所有直系和非直系下属中能力比他高的最忠诚的人是谁 思路:因为树上查询很麻烦,所以我们直 ...

  5. Deep Reinforcement Learning for Visual Object Tracking in Videos 论文笔记

    Deep Reinforcement Learning for Visual Object Tracking in Videos 论文笔记 arXiv 摘要:本文提出了一种 DRL 算法进行单目标跟踪 ...

  6. Docker:Containers

    Prerequisites Install Docker version 1.13 or higher. Read the orientation in Part 1. Give your envir ...

  7. 【Oracle】【问题】

    1. java.sql.SQLException: 对只转发结果集的无效操作: last 参考:https://www.cnblogs.com/gaoyuchuanIT/articles/411888 ...

  8. [osg]osg背景图设置

    转自:https://blog.csdn.net/qq_30754211/article/details/61190698 #include <osg/Geometry> #include ...

  9. 后端调用接口在通过webService发布 解决跨域问题

    1.新建一个空的项目 2.添加一个WebService新项   asmx格式的 3.在这里面写方法  加上[WebMethod]标识 前端就可以调用 4.发布WebService  右键服务  添加服 ...

  10. sass、less是什么,如何使用?

    一个很好的介绍的SASS,LESS的区别的文档,值get 1.背景介绍 CSS 是一门非程序式语言,没有变量.函数.SCOPE(作用域),需要书写大量看似没有逻辑的代码,不方便维护及扩 展,不利于复用 ...