zoukankan      html  css  js  c++  java
  • [BZOJ1002] [FJOI2007] 轮状病毒 (数学)

    Description

    给定n(N<=100),编程计算有多少个不同的n轮状病毒。

    Input

    第一行有1个正整数n。

    Output

    将编程计算出的不同的n轮状病毒数输出

    Sample Input

    3

    Sample Output

    16

    HINT 

    Source

    Solution

      基尔霍夫矩阵,左转生成树的计数及其应用

      推出本题的递推式:f[n] = f[n - 1] * 3 - f[n - 2] + 2

      如果你能看懂,拜托给我讲讲,本人不懂。

      注意要使用高精度

     1 #include <cstring>
     2 #include <iostream>
     3 #include <algorithm>
     4 using namespace std;
     5 struct bigint
     6 {
     7     int a[55];
     8  
     9     bigint()
    10     {
    11         memset(a, 0, sizeof(a));
    12     }
    13  
    14     bigint operator + (int rhs)
    15     {
    16         bigint ans;
    17         for(int i = 0; i <= a[0]; i++)
    18             ans.a[i] = a[i];
    19         ans.a[0]++, ans.a[1] += rhs;
    20         for(int i = 1; i < ans.a[0]; i++)
    21         {
    22             ans.a[i + 1] += ans.a[i] / 10;
    23             ans.a[i] %= 10;
    24         }
    25         while(!ans.a[ans.a[0]])
    26             ans.a[0]--;
    27         return ans;
    28     }
    29  
    30     bigint operator - (bigint rhs)
    31     {
    32         bigint ans;
    33         ans.a[0] = a[0];
    34         for(int i = 1; i <= ans.a[0]; i++)
    35             ans.a[i] = a[i] - rhs.a[i];
    36         for(int i = 1; i < ans.a[0]; i++)
    37             if(ans.a[i] < 0)
    38             {
    39                 ans.a[i] += 10;
    40                 ans.a[i + 1] -= 1;
    41             }
    42         while(!ans.a[ans.a[0]])
    43             ans.a[0]--;
    44         return ans;
    45     }
    46  
    47     bigint operator * (int rhs)
    48     {
    49         bigint ans;
    50         ans.a[0] = a[0] + 1;
    51         for(int i = 1; i <= ans.a[0]; i++)
    52             ans.a[i] = a[i] * rhs;
    53         for(int i = 1; i < ans.a[0]; i++)
    54         {
    55             ans.a[i + 1] += ans.a[i] / 10;
    56             ans.a[i] %= 10;
    57         }
    58         while(!ans.a[ans.a[0]])
    59             ans.a[0]--;
    60         return ans;
    61     }
    62  
    63 }f[105];
    64  
    65 int main()
    66 {
    67     int n;
    68     cin >> n;
    69     f[1].a[1] = 1, f[2].a[1] = 5;
    70     f[1].a[0] = f[2].a[0] = 1;
    71     for(int i = 3; i <= n; i++)
    72         f[i] = f[i - 1] * 3 - f[i - 2] + 2;
    73     for(int i = f[n].a[0]; i; i--)
    74         cout << f[n].a[i];
    75     cout << endl;
    76     return 0;
    77 }
    View Code
  • 相关阅读:
    TXLSReadWriteII 公式计算
    Delphi TXLSReadWriteII2 带的demo中直接编辑XLS文件的例子
    delphi图片欣赏
    SQL 读取csv 文件批量插入数据
    Delphi TXLSReadWriteII 导出EXCEL
    Rollup 与 webpack的区别
    ref 属性使用eslint报错
    内容超出省略实现
    mac 环境配置
    前端学习资料整理
  • 原文地址:https://www.cnblogs.com/CtrlCV/p/5350928.html
Copyright © 2011-2022 走看看