美文网首页
算法 Plan

算法 Plan

作者: 这是个懒得不想动脑的昵称 | 来源:发表于2019-04-14 14:50 被阅读0次

Qingdao Institute of Technology is the highest academic institution in Jiaozhou, so it has extremely strict discipline. In order to get a good grades, Li had to prepare a review route in advance to cope with the fianl exam. There are n liberal arts exams in this semester, and there are 4 exam subjects, namely politics, history, geography and comprehensive course . Every time you take a test but it is uncertain, so Li don't know which course to review before the exam. He hopes to predict the exams that may be tested next time. So he collected information in previous liberal arts exams. From the previous exams, he discovered several rules:

If the test is political, then the next time you will test the history;
If the test is comprehensive course, then the next time you will test the geography;
If the test is history, then the next time you will take politics or geography;
If the test is geography, then the next time you either take history or the comprensive course. Li already knows that the first exam in this semester is political. He intends to develop an exam review plan that can address all possible situations. Therefore, he would like to know how many possible test subjects are arranged throughout the semester to meet the above rules.
输入格式:
A positive integer n represents the total number of exams for the semester. The input data is guaranteed to be n<=10000.

输出格式:
A positive integer indicating the total number of subject arrangements for the rule. Considering that this result can be very large, you only need to output the value of mod 7654321.

输入样例:
5
输出样例:
5


import sys
#修改默认最大递归深度
sys.setrecursionlimit(1000000)

def fun(n):
    if li[n] != 0:
        return li[n]
    else:
        li[n] = fun(n-1) % 7654321 + fun(n-2) % 7654321
        return li[n]

if __name__ == "__main__":
    li = [0 for n in range(10001)]
    li[0] = li[1] = li[2] = 1
    n = int(input())
    print(fun(n) % 7654321)

相关文章

  • 2016.08.08

    plan axure/node/express/ 工作/算法工作 axure 算法 express node 健身...

  • 算法 Plan

    Qingdao Institute of Technology is the highest academic i...

  • 2016.08.06

    plan 主题: 算法/axure/express 复习算法题目,顺便加深对 es6的理解与运用 axure 仿照...

  • 优化算法work plan

    贝叶斯优化->强化学习优化->PBT

  • 16/100

    plan: 上午:6.3完; 算法图解,广度优先搜索,下一章; 下午: 整理abstract&introducti...

  • 2016.08.05

    plan axure/node/express, 有精力再看下算法 axure罗列出可以实现的初级效果,并熟悉 a...

  • 15/100

    plan: 上午: 6.2写完 做Fp图,写这段文字 中午:洗澡 下午: lda 6.3改完 算法图解 晚上,开会...

  • 学习二分查找算法

    学习计划 在力扣的网站上有关于算法的学习计划:https://leetcode-cn.com/study-plan...

  • 2017-12-10

    Daily Routine plan performance plan

  • 2017-12-09

    Daily routine plan performing plan

网友评论

      本文标题:算法 Plan

      本文链接:https://www.haomeiwen.com/subject/oizjwqtx.html