【题目描述】

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

【输入格式】

第一行有1个正整数n。

【输出格式】

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

【样例输入】

3

【样例输出】

16

【题目来源】

耒阳大世野(衡阳八中) OJ 1002

(福建省选赛2007)

【分析】

从“各原子有唯一的信息通道”不难看出,每种轮状病毒对应着轮状基的一棵生成树。一般图的生成树计数可以用Matrix-Tree 定理求解,但这里的图比较特殊,用Matrix-Tree未免有些小题大做, 我们可以用组合递推的方法求解。

先设$f(n)$为n轮状基上删去一条弧得到的“缺口轮”上的生成树个数,再设$S(n) = \sum \limits_{i = 1}^n {f(i)}$. 于是就有:

$$\begin{array}{F} f(0) = f(1) = 1\\ f(n) = 2f(n-1) + \sum_{i=0}^{n-2} f(i) = f(n-1) + S(n-1) + 1 \end{array}$$

$$ans(n) = f(n) + 2\sum_{i = 1}^{n-1}f(i) = S(n) + S(n-1)$$

    (这个公式我推了一上午我会说?)

考虑到n最大为100,答案会超过long long的范围,这里的状态值应用高精度类存储。

 1 /**************************************************************
 2     Problem: 1002
 3     User: 935671154
 4     Language: C++
 5     Result: Accepted
 6     Time:44 ms
 7     Memory:2068 kb
 8 ****************************************************************/
 9  
 //Author : Asm.Def
 #include <iostream>
 #include <cctype>
 #include <cstdio>
 #include <vector>
 #include <algorithm>
 #include <cmath>
 #include <queue>
 using namespace std;
 inline void getd(int &x){
     char c = getchar();
     bool minus = ;
     while(!isdigit(c) && c != '-')c = getchar();
     if(c == '-')minus = , c = getchar();
     x = c - '';
     while(isdigit(c = getchar()))x = x *  + c - '';
     if(minus)x = -x;
 }
 /*======================================================*/
 const int maxn = ;
  
 struct BigN{
     #define base 10000
     #define maxl 1000
     int A[maxl], len;
     BigN(){len = , A[] = ;}
     BigN &operator = (const BigN &x){
         len = ;
         while(len < x.len){A[len] = x.A[len]; ++len;}
         return *this;
     }
     BigN &operator = (int k){len = ;A[] = k; return *this;}
     BigN &operator += (const BigN &x){
         int i, mor = ;
         for(i = ;i < x.len || mor;++i){
             if(i < len)mor += A[i];
             if(i < x.len)mor += x.A[i];
             A[i] = mor % base;
             mor /= base;
         }
         if(i > len)len = i;
         return *this;
     }
 }f[maxn], S[maxn];
  
 inline void work(int k){
     int i;
     if(!k){printf("0\n");return;}
     f[] = , f[] = , S[] = ;
     if(k == ){printf("1\n");return;}
     for(i = ;i <= k;++i){
         f[i] = ; f[i] += f[i-]; f[i] += S[i-];
         S[i] = S[i-]; S[i] += f[i];
     }
     S[k] += S[k-];
     i = S[k].len - ;
     printf("%d", S[k].A[i]);
     while(i)
         printf("%04d", S[k].A[--i]);
     putchar('\n');
 }
      
 int main(){
     #if defined DEBUG
     freopen("test", "r", stdin);
     #endif
     int k;
     getd(k);
      
     work(k);
      
     #if defined DEBUG
     cout << endl << (double)clock()/CLOCKS_PER_SEC << endl;
     #endif
     return ;
 }

高精度 + 递推

最新文章

  1. Eclipse注释模板设置详解
  2. EEG preprocessing - A Trick Before Doing ICA
  3. CSS 页面顶部阴影和给浏览器强制加上滚动条
  4. yum
  5. EntityFramework Reverse POCO Code First 生成器
  6. Spring声明式事务管理基于@Transactional注解
  7. 自定义EditText实现可以一键删除输入的内容
  8. [Unity2D]鼠标(或触摸)输入处理
  9. Kinetic使用注意点--animation
  10. mysql left用法
  11. Sybase自增字段跳号的解决方法
  12. 201521123073 《Java程序设计》第1周学习总结
  13. 43.Linux调试测试输入思路
  14. Extending the Yahoo! Streaming Benchmark
  15. C#实现按键计算器功能
  16. go defer笔记
  17. 将Long类型转为字母数字组合的jar包---Hashids
  18. 如何用jquery实现实时监控浏览器宽度
  19. mint-ui Picker的使用
  20. day 09 初识函数

热门文章

  1. python中BeautifulSoup模块
  2. 双内网渗透代理之reGeorg+Proxifier
  3. 网络设备之pci_driver
  4. Linux内核中内存cache的实现【转】
  5. centos 挂在ntfs
  6. udpserver.pl 和 udpclient.pl
  7. Load balancer does not have available server for client:xxx
  8. linux和性能相关的命令及系统性能诊断
  9. mac date 和 Linux date实现从指定时间开始循环
  10. connect-falsh的用法